Reputation: 1905
Given a git repository that has a .gitignore
pointing towards bar/foo/file
adding that file prints it fails adding them – it should require forcing through -f
– while at the same time actually adding them.
More precisely the following command and its outputs are confusing:
$ 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
Note that the last command (git diff
) should have no output if no file was changed.
To better retrace this, consider these commands:
$ 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
Is this desired bevahiour? Is this a bug?
Upvotes: 2
Views: 352
Reputation: 60565
The file was already tracked. I agree the hint is wrong, you've found a corner case the newbie-helper logic didn't anticipate. I'd recommend git config advice.addignoredfile false
.
Upvotes: 4