127

I want git to stop tracking my local development log (log/development.log) in our repositories. Is this possible and how can I do it?

IAmNaN
  • 10,305
  • 3
  • 53
  • 51
Splashlin
  • 7,225
  • 12
  • 46
  • 50
  • possible duplicate of [Making git "forget" about a file that *was* tracked but is now ".gitignored"](http://stackoverflow.com/questions/1274057/making-git-forget-about-a-file-that-was-tracked-but-is-now-gitignored) – Cascabel Nov 08 '10 at 14:45

3 Answers3

144

Just to give the full answer all at once:

  1. from klemens: You need to add the file to your .gitignore file somewhere above the undesired file in the repo. i.e.

    $ cd $ cat >> .gitignore development.log C-d

  2. from m. narebski: You then need to remove the file from the repo by executing "git rm --cached <file> and then committing this removal"

If you were also hoping to make the repo look as if it had never tracked that file, that is much more complicated and highly discouraged as it not only creates brand new commits for every single commit in your history, thus destroying interoperability in a nasty way between other people who have cloned your repo, but it also leaves every one of those commits untested (assuming you test your commits before making them).

With that caveat in mind, the tool you're looking for if that's your goal is filter-branch. The first example does exactly what I'm describing.

Tim Visher
  • 12,786
  • 16
  • 58
  • 66
  • 3
    using git rm --cached seems to have not only removed it my the branch, but when I pull to another system it deletes the files physically on that system. Any idea what's going on there? – biagidp Oct 13 '11 at 21:08
  • 2
    In response to the above: I believe the issue was in that I did not have .gitignore in place on the alternate system before pulling the changes, so the delete removed the local copy. At least that's the theory – biagidp Oct 13 '11 at 21:14
54

To stop tracking the file, simply use git rm --cached <filename>.

But as pointed out by the others here, adding the file to .gitignore might prevent you from accidentally adding it again later.

kusma
  • 6,516
  • 2
  • 22
  • 26
1

add the gitignore file.

see http://git-scm.com/docs/gitignore

fetzig
  • 1,642
  • 1
  • 13
  • 25
  • 13
    This is only half of the answer. `.gitignore` entries don't apply to files that are already being tracked. – CB Bailey Nov 08 '10 at 14:39
  • 10
    The second part is `git rm --cached ` and then comitting this removal. – Jakub Narębski Nov 08 '10 at 15:42
  • 1
    Why isn't there a simple command for git to reevaluate all currently tracked files according to the current .gitignore file? ...or is that exerting far too much common sense? :p – Alexander Jul 18 '14 at 08:52