Git Reset, Revert, and Restore Cheat Sheet

Understand the differences between reset, revert, and restore and use the right recovery command safely.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Reset Basics

Move branch tips and manipulate the index intentionally.

Undo last commit but keep everything staged

Move HEAD back one commit while preserving index and working tree.

bashANYgitresetsoftundo
bash
git reset --soft HEAD~1

Great for rewriting the latest commit while keeping all changes ready to recommit.

Undo last commit and unstage changes

Move HEAD back one commit and leave changes in the working tree.

bashANYgitresetmixedundo
bash
git reset --mixed HEAD~1

`--mixed` is the default reset mode and is commonly used when you want to recommit changes differently.

Discard last commit and local changes

Move HEAD back one commit and discard index and working tree changes.

bashANYgitresetharddanger
bash
git reset --hard HEAD~1

Very destructive locally. Use only when you are sure you want to discard the changes.

Unstage a single file

Remove a path from the index without changing its contents in the working tree.

bashANYgitresetunstageindex
bash
git reset HEAD path/to/file

Classic staging-area reset for one path. Modern workflows may also use `git restore --staged`.

Reset out of a conflicted merge state

Try to leave local changes intact while backing out of a merge-like operation.

bashANYgitresetmergerecovery
bash
git reset --merge ORIG_HEAD

Useful after failed merge or pull operations. Git documents `--merge` as intended for resetting out of conflicted merges.

Revert Basics

Create new commits that reverse previous commits.

Revert a single commit

Create a new commit that reverses an earlier commit.

bashANYgitrevertundohistory
bash
git revert <commit_sha>

Preferred for undoing already-shared history because it preserves the public timeline.

Revert several commits without auto-committing

Apply inverse changes into the index and working tree first.

bashANYgitrevertrangehistory
bash
git revert --no-commit <start_commit>^..<end_commit>

Useful when combining multiple reversions into a single manual commit.

Revert a merge commit

Reverse a merge relative to a chosen parent.

bashANYgitrevertmergemainline
bash
git revert -m 1 <merge_commit_sha>

Reverting a merge requires specifying the mainline parent. Be careful because later merges can behave differently after this.

Continue a conflicted revert

Resume revert after resolving conflicts.

bashANYgitrevertcontinueconflicts
bash
git revert --continue

Revert can stop on conflicts just like cherry-pick and rebase.

Restore Basics

Restore file content from the index or another revision.

Discard unstaged changes in a file

Restore a file in the working tree from the index.

bashANYgitrestoreworking-treeundo
bash
git restore path/to/file

Modern command for throwing away local unstaged edits to a path.

Unstage a file with restore

Restore the index entry for a path from HEAD.

bashANYgitrestorestagedindex
bash
git restore --staged path/to/file

Modern alternative to `git reset HEAD path/to/file` when you only want to affect the staging area.

Restore a file from another commit

Copy file contents from a specific commit into the working tree.

bashANYgitrestoresourcefile
bash
git restore --source=<commit_sha> path/to/file

Useful when you need one path as it existed in a different revision without moving branch history.

Interactively restore hunks

Select portions of a file to restore interactively.

bashANYgitrestorepatchinteractive
bash
git restore --patch path/to/file

Powerful for partial undo operations at hunk granularity.

Restore both index and working tree from another commit

Reset a file to another revision in both staging area and working tree.

bashANYgitrestorestagedworktree
bash
git restore --source=<commit_sha> --staged --worktree path/to/file

Useful when you want a path to match another commit exactly in both locations.

Decision Guide

Choose the right undo command for the situation.

Mental model for reset vs restore vs revert

Quick decision guide for the three similarly named commands.

textANYgitresetrestorerevert
text
reset = move branch/history
restore = restore file content/index state
revert = add new commit that undoes old commit

Git’s official guidance distinguishes these commands clearly: reset moves refs/history, restore restores files/index, and revert records new inverse commits.

Create a safety branch before destructive changes

Save a recovery pointer before hard reset or risky history edits.

bashANYgitsafetybackuprecovery
bash
git branch backup-before-reset

A simple but strong safeguard before destructive operations like hard reset or forceful history rewriting.

Use reflog after a mistaken reset

Find the previous branch tip after a bad reset.

bashANYgitreflogresetrecovery
bash
git reflog

If you used the wrong reset mode or target, reflog is usually the fastest path back.

Recommended next

No recommendations yet.