1

if i forget igonore a file before pusing a project, what should i do.?

I have an already initialized Git repository that I added a .gitignore file to. How can I refresh the file index so the files I want ignored get ignored?

  • same issues: https://stackoverflow.com/questions/1274057/how-do-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore?rq=2 – whidy Mar 30 '23 at 09:41
  • Does this answer your question? [How do I make Git forget about a file that was tracked, but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-do-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – Fastnlight Mar 30 '23 at 14:31

1 Answers1

0

"How do I make Git forget about a file that was tracked, but is now in .gitignore?" address the main points:

  • git rm --cached -- file-which-should-be-ignored
  • remove file from the repository history (IE, from the past commits)

If your .gitignore was already set to ignore that file, said file will be ignored as soon as it is deleted (from the perspective of Git)

But removing the file from past commits is mentioned using the old git filter-branch command.

Nowadays, git filter-repo is recommended (to be installed first), using path-based filtering:

git filter-repo --invert-paths --path 'path/to/file/to/ignore' 
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250