除了mercurial之外,我还尝试使用git,并将我的.hgignore文件作为起点。
我的.gitignore file包含以下行:
./homeautomation/homeassistant/home-assistant_v2.db
我已经确保没有.git目录,然后我初始化了repo并进行了添加和提交。我使用了忽略错误选项,因为其中一些文件正在使用中。
wb@docker:~/stacks$ git init
Initialized empty Git repository in /home/wb/stacks/.git/
wb@docker:~/stacks$ git add . --ignore-errors
error: open("homeautomation/homeassistant/.storage/auth"): Permission denied
error: unable to index file homeautomation/homeassistant/.storage/auth
error: open("network/pihole/pihole/list.0.raw.githubusercontent.com.domains"): Permission denied
error: unable to index file network/pihole/pihole/list.0.raw.githubusercontent.com.domains
error: open("network/pihole/pihole/list.1.mirror1.malwaredomains.com.domains"): Permission denied
error: unable to index file network/pihole/pihole/list.1.mirror1.malwaredomains.com.domains
error: open("network/pihole/pihole/list.3.zeustracker.abuse.ch.domains"): Permission denied
error: unable to index file network/pihole/pihole/list.3.zeustracker.abuse.ch.domains
error: open("network/pihole/pihole/list.6.hosts-file.net.domains"): Permission denied
error: unable to index file network/pihole/pihole/list.6.hosts-file.net.domains
wb@docker:~/stacks$当我执行提交时,我看到提交消息中提到了以下文件:
新文件: homeautomation/homeassistant/home-assistant_v2.db
这是尽管.gitignore文件被专门设置为忽略该文件。
我运行了以下命令:
git ls- ./homeautomation/homeassistant/home-assistant_v2.db文件
它返回了文件名。读了几遍之后,我做了以下几件事。
wb@docker:~/stacks$ git rm --cached ./homeautomation/homeassistant/home-assistant_v2.db
error: the following file has staged content different from both the
file and the HEAD:
homeautomation/homeassistant/home-assistant_v2.db
(use -f to force removal)
wb@docker:~/stacks$然后,我使用“force”选项再次运行命令,文件就从提交消息中消失了。
我的问题是,为什么我必须使用git rm —cached,因为文件本来就不应该添加?启动时没有.git目录。
发布于 2019-05-01 22:40:44
您的.gitignore文件中有一个不应该包含的./。假设文件相对于存储库的顶层,只要.gitignore文件也是如此。如果您删除了./,那么应该正确地忽略您的文件。
https://stackoverflow.com/questions/55943566
复制相似问题