37

How do I remove a file from a git repositorie's index without removing the file from the working tree?

If I had a file ./notes.txt that was being tracked by git, I could run git rm notes.txt. But that would remove the file. I'd rather want git just to stop tracking the file.

Stefan
  • 25,300

3 Answers3

54

You could just use git rm --cached notes.txt. This will keep the file but remove it from the index.

Gert
  • 9,994
3

git reset HEAD <file> for removing a particular file.

and git reset HEAD for removing all files from the git index.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • That answer appeared 8 years after Gert's solution, has semantic of git reset command changed since that time? – Kamil Apr 26 '19 at 06:36
0

git restore --staged <file> worked fine for me