This is an old revision of the document!
Overview
Various ways to undo, backpedal and regret.
Undoing uncommitted changes
Throwing away all staged and unstaged changes
If you have no interest in any of the local changes (staged or unstaged):
$ git reset --hard
Understand … they're gone.
Undoing unstaged changes (part one)
From man git-checkout:
git checkout [<tree-ish>] [--] <pathspec>...
Overwrite paths in the working tree by replacing with the
contents in the index or in the <tree-ish> (most often a
commit). When a <tree-ish> is given, the paths that match
the <pathspec> are updated both in the index and in the
working tree.
To undo some local (unstaged) edits to README, overwrite your working tree copy with the copy from the index:
$ git checkout -- README
To undo all unstaged changes:
$ git checkout -- .
Undoing unstaged changes (part deux)
If you have already staged some changes, made additional changes and want to undo just those local (unstaged) changes, see above.
$ git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: README Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: README $
Discard unstaged changes:
$ git checkout -- README
End result:
$ git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: README
Undoing all staged and unstaged changes
git checkout [<tree-ish>] [--] <pathspec>...
Overwrite paths in the working tree by replacing with the
contents in the index or in the <tree-ish> (most often a
commit). When a <tree-ish> is given, the paths that match
the <pathspec> are updated both in the index and in the
working tree.
To overwrite with the most recently committed version of the file:
$ git checkout HEAD -- README
Recall how to do this for everything:
$ git reset --hard