0

I want to ignore the single file in git, which is already committed in git. but I am not able to do this. Please provide any solution.

pmali
  • 67
  • 1
  • 6
  • 3
    Does this answer your question? [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – anishtain4 Nov 26 '20 at 17:40

1 Answers1

2

If you want to ignore it moving forward, then you can add the file to .gitignore, then do this:

git rm --cached the-file # remove from index.... keep the file on the working tree
git commit -m "Removing file so that it can be ignored"

From this moment on, the file will be ignored. This still has problems... for example: you want to checkout a revision that is older, when the file was not being ignored. Git will complain.... so you force it... git checks out... then you come back, and the file is gone. You can still get it back, of course, but that doesn't make it less bothersome.

The other thing you can do is rewrite history so that the file is gone from historic revisions.... but that presents its own set of problems and implications so the decision to go down this path should not be carried out lightly.

eftshift0
  • 26,375
  • 3
  • 36
  • 60