Sometimes git suggests git rm --cached
to unstage a file, sometimes git reset HEAD file
. When should I use which?
EDIT:
D:\
These 2 commands have several subtle differences if the file in question is already in the repo and under version control (previously committed etc.):
git reset HEAD
unstages the file in the current commit.git rm --cached
will unstage the file for future commits also. It's unstaged untill it gets added again with git add
.And there's one more important difference:
git rm --cached
and push your branch to the remote, anyone pulling your branch from the remote will get the file ACTUALLY deleted from their folder, even though in your local working set the file just becomes untracked (i.e. not physically deleted from the folder).This last difference is important for projects which include a config file where each developer on the team has a different config (i.e. different base url, ip or port setting) so if you're using git rm --cached
anyone who pulls your branch will have to manually re-create the config, or you can send them yours and they can re-edit it back to their ip settings (etc.), because the delete only effects people pulling your branch from the remote.