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.

3 Answers 3

54

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

3

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

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

1
  • That answer appeared 8 years after Gert's solution, has semantic of git reset command changed since that time?
    – Kamil
    Apr 26, 2019 at 6:36
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .