Skip to main content

Undo commits or unstage changes, by resetting the current git HEAD to the specified state. If a path is passed, it works as "unstage"; if a commit hash or branch is passed, it works as "uncommit".

# To unstage everything:
git reset

# To unstage specific file(s):
git reset <path/to/file(s)>

# To unstage portions of a file:
git reset -p <path/to/file>

# To undo the last commit, keeping its changes (and any further uncommitted changes) in the filesystem:
git reset HEAD~

# To undo the last two commits, adding their changes to the index, i.e. staged for commit:
git reset --soft HEAD~2

# To discard any uncommitted changes, staged or not (for only unstaged changes, use 'git checkout'):
git reset --hard

# To reset the repository to a given commit, discarding committed, staged and uncommitted changes since then:
git reset --hard <commit>