5

I have untracked some folders and files by using .git/info/exclude :

doc
*.txt
doc/*.txt
doc/somefile.txt

But git status says it is still tracked :

$ git st
# On branch dev
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   doc/somefile.txt

Other weird thing is that ls-files shows it is untracked :

$ git ls-files --ignored --exclude-from=.git/info/exclude
doc/somefile.txt
$ touch /tmp/xxx
$ git ls-files --ignored --exclude-from=/tmp/xxx
$

I am on git version 1.8.1.5

So I conclude I may misunderstand something or do something wrong. Any idea please ?

lalebarde
  • 1,684
  • 1
  • 21
  • 36

3 Answers3

6

Since you are locally ignoring files that are in the repository, you need to tell git that you are ignoring them

git update-index --assume-unchanged <files to forget>
Abizern
  • 146,289
  • 39
  • 203
  • 257
  • 1
    This is the right answer. @lalebarde, I can add you are not `untracking` the files, you are ignoring them. They are already tracked, therefore you have to follow @Abizern's advice to let git forget them. Check [this explanation](http://source.kohlerville.com/2009/02/untrack-files-in-git/) to know why `update-index` is a better solution than `rm --cached` – ThanksForAllTheFish Aug 16 '13 at 12:35
  • That command was never meant to solve this type of problem, and using it as such is considered a bad idea by the developers of git. It was meant as a way to improve performance in some situations. Git will take that as a promise that the file won't be changed underneath it, but that won't be at all true in this case. Using `git stash` after this has been done is likely to lead to the local changes being lost. See the thread around http://article.gmane.org/gmane.comp.version-control.git/225308 . There may be problems with this in other cases as well. – qqx Aug 16 '13 at 13:36
3

You need to git rm --cached <file>. This doesn't remove the file from your working directory, but it removes it from the git cache so it'll now be included by the .gitignore.

Nicholas Smith
  • 11,642
  • 6
  • 37
  • 55
0

Since the file(s) is currently beeing tracked, you need to tell gitto forget about them before ignoring them.

git rm --cached doc/somefile.txt

jlundqvist
  • 651
  • 3
  • 10