Reputation: 69757
I usually do this:
git init
git add .
git commit .
And then I realize that it's about to add my nbproject directory, which I want excluded/ignored. Sometimes, I even check in this directory. Had I added it to .git/info/exclude before running git add .
, everything would have worked fine (it's excluded).
So then I modify .git/info/exclude and then it's too late. Git no longer respects changes to .git/info/exclude.
So the questions are:
git add .
again, which doesn't help)Upvotes: 26
Views: 12775
Reputation: 993085
To remove a file that you have added but not committed, use a command like this:
git rm --cached file.to.remove
This will remove the file from the index, but not touch the file on disk.
To remove a file (or files) from the most recent commit, use the above git rm --cached
command followed by git commit --amend
.
Upvotes: 40