Git Reset

The git reset command is for "resetting" the current HEAD to a specified state.

Command Description
git reset HEAD this will unstage a file, HEAD is the last commit
git reset HEAD~ undo the last commit, moving those changes back into the working area, so you can work on it again and then commit again
git reset --soft moves stuff back to staging
git reset --soft HEAD~ undo last commit, note that “HEAD^” means commit before the current HEAD
git reset or git reset --mixed moves changes to working directory
git reset --hard moves change to the trash or recycle bin, throwing them away, staging and working directory changes are lost
git reset --hard origin/master throw away all changes and align to remote branch
git reset --hard HEAD~ Undo last commit and all changes
git reset --hard HEAD~~ Undo last two commits and all changes
git reset --mixed <sha> move HEAD back to this commit

The git reset command allows you to move commits from history into the working directory or staging, and you can also throw changes away. It is best to not do this after changes have been pushed to origin, as others might then have these changes and then you can enter a deep world of pain among the team.

If you do a git reset --hard HEAD~ then it is possible to get this commit back, if that was a mistake, look in the reflog for the SHA and use git reset --hard <sha>, and then git log will show this has worked.

See also: