git rm
will remove entries from the staging area. This is a bit different fromgit 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 usegit rm --cached
.
But what exactly is the difference between git rm --cached asd
and git reset head -- asd
?
git rm --cached file
will remove the file from the stage. That is, when you commit the file will be removed. git reset HEAD -- file
will simply reset file in the staging area to the state where it was on the HEAD commit, i.e. will undo any changes you did to it since last commiting. If that change happens to be newly adding the file, then they will be equivalent.
Perhaps an example will help:
git rm --cached asd
git commit -m "the file asd is gone from the repository"
versus
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.
Source: Stackoverflow.com