Explore Courses Blog Tutorials Interview Questions
+4 votes
1 view
in DevOps and Agile by (19.7k points)

git rm will remove entries from the staging area. This is a bit different from git reset HEAD which "unstages" files. By "unstage" I mean it reverts the staging area to what was there before we started modifying things.  git rm on the other hand just kicks the file off the stage entirely, so that it's not included in the next commit snapshot, thereby effectively deleting it.

By default, a git rm file will remove the file from the staging area entirely and also off your disk > (the working directory). To leave the file in the working directory, you can use git rm --cached.

But what exactly is the difference between git rm --cached asd and git reset head -- asd? 


1 Answer

+7 votes
by (62.9k points)
selected by
Best answer

An example would help:

git rm --cached asd

git commit -m "the file asd is being removed from the repository"


git reset HEAD -- asd

git commit -m "the file asd remains in the repository"

Note that if you haven't changed anything else, the second commit won't actually do anything.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories