tags:

views:

697

answers:

5

There's this file that was being tracked at one time by git, but now the file is on the .gitignore list.

However, that file keeps showing up in git st after it's edited, so how would you force git to completely forget about it?

A: 

move it out, commit, then move it back in. This has worked for me in the past. There is probably a 'gittier' way to accomplish this.

Joel Hooks
+1  A: 

Move or copy the file to a safe location, so you don't lose it. Then git rm the file and commit. The file will still show up if you revert to one of those earlier commits, or another branch where it has not been removed. However, in all future commits, you will not see the file again. If the file is in the git ingore, then you can move it back into the folder, and git won't see it.

Apreche
`git rm --cached` will remove the file from the index without deleting it from disk, so no need to move/copy it away
bdonlan
@bdonlan, better to provide your own answer then :)
hasen j
A: 

Dan Glegg edits .git/info/exclude.

mcandre
A: 

I accomplished this by using git filter-branch. The exact command I used was taken from the man page:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD

This command will recreate the entire commit history, executing git rm before each commit and so will get rid of the specified file. Don't forget to back it up before running the command as it will be lost.

spatz
This will change all commit IDs, thus breaking merges from branches outside of your copy of the repository.
bdonlan
+6  A: 

.gitignore will prevent untracked files from being added (without an add -f) to the set of files tracked by git, however git will continue to track any files that are already being tracked.

To stop tracking a file you need to remove it from the index. This can be achieved with this command.

git rm --cached <file>

The removal of the file from the head revision will happen on the next commit.

Charles Bailey
the process that workd for me was1. commit pending changes first2. git rm --cached <file> and commit again3. add the file to .gitignore, check with git status and commit again
mataal