Git表示,据称它忽略了文件,但实际上添加了它们



给定一个git存储库,其.gitignore指向bar/foo/file,添加该文件打印时无法添加它们——应该需要强制通过-f——同时实际添加它们。更确切地说,以下命令及其输出令人困惑:

$ git add bar/foo/file       
The following paths are ignored by one of your .gitignore files:
bar
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"
$ git diff --cached
diff --git a/bar/foo/file b/bar/foo/file
index d00491f..0cfbf08 100644
--- a/bar/foo/file
+++ b/bar/foo/file
@@ -1 +1 @@
-1
+2

请注意,如果没有更改任何文件,则最后一个命令(git diff(应该没有输出。

为了更好地追溯这一点,请考虑以下命令:

$ cd $(mktemp -d)
$ git init
$ mkdir -p bar/foo
$ echo 1 > bar/foo/file
$ git add .
$ git commit -m 1
$ echo bar > .gitignore
$ git add .
$ git commit -m gi
$ echo 2 > bar/foo/file
$ git add foo/bar/file
$ git status

这是想要的饮料吗?这是个虫子吗?

文件已被跟踪。我同意这个提示是错误的,你已经发现了一个新手助手逻辑没有预料到的角落案例。我推荐git config advice.addignoredfile false

最新更新