Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

How to remove a file from the index ( = staging area = cache) without removing it from the file system?

1 Answer

0 votes
by (27.5k points)

Since you want to remove a file from the index without removing it from the file system, I would suggest you to use the following command: 

$ git rm --cached [file]

Even if you omit the --cached option, it will be deleted it from the working tree. I would also like to mention that git rm is slightly safer than git reset, because you'll be warned if the staged content doesn't match either the tip of the branch or the file on disk. (If it doesn't, you have to add --force.)

Browse Categories

...