首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.gitignore并没有忽略新存储库上的文件。文件缓存中有比.git目录更多的内容吗?

.gitignore并没有忽略新存储库上的文件。文件缓存中有比.git目录更多的内容吗?
EN

Stack Overflow用户
提问于 2019-05-01 22:37:12
回答 1查看 79关注 0票数 0

除了mercurial之外,我还尝试使用git,并将我的.hgignore文件作为起点。

我的.gitignore file包含以下行:

./homeautomation/homeassistant/home-assistant_v2.db

我已经确保没有.git目录,然后我初始化了repo并进行了添加和提交。我使用了忽略错误选项,因为其中一些文件正在使用中。

代码语言:javascript
复制
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文件

它返回了文件名。读了几遍之后,我做了以下几件事。

代码语言:javascript
复制
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目录。

EN

回答 1

Stack Overflow用户

发布于 2019-05-01 22:40:44

您的.gitignore文件中有一个不应该包含的./。假设文件相对于存储库的顶层,只要.gitignore文件也是如此。如果您删除了./,那么应该正确地忽略您的文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55943566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档