Dan Rosenstark
Dan Rosenstark

Reputation: 69757

How can I work with file '.git/info/exclude' too late?

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:

  1. How can I get Git to take up the changes in the exclude file in the checkin? (I tried running git add . again, which doesn't help)
  2. Let's say I check in a directory (or file) that I want excluded. What is the least number of steps to get to the state I want? (with the file excluded).

Upvotes: 26

Views: 12775

Answers (1)

Greg Hewgill
Greg Hewgill

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

Related Questions