Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Git Reset

Reset changes what commit HEAD points to. This is one way to undo a bad local commit, or a series of bad local commits.

Reset always modifies history.

Soft Reset

AKA, Squashing

  • Move HEAD.
  • Do not modify the Index.
  • Do not modify the Working Tree.

This is useful to undo local commits then re-play them as one commit.

e.g, you don’t need to git add the files are already in the Index.

git reset --soft HEAD~3
git commit

Mixed Reset

Creates Intermediate Commits.

  • Move HEAD.
  • Reset Index to HEAD
  • Do not modify the Working Tree.

Maybe you made 5 local commits but you’d prefer if it was 2.

git reset --mixed HEAD~5
git add file1.c
git add file2.c
git commit -m "Intermediate Commit 1"
git add file3.c
git add file4.c
git commit -m "Final commit"

Hard Reset

Caution

This erases uncommitted work. This creates dangling local commits.

  • Move HEAD
  • Reset Index to HEAD
  • Reset Working Tree to HEAD
git fetch origin
git reset --hard origin/main

References

Git - git-reset Documentation

Last Modified • Sunday, June 14, 2026. 5:09 am UTC+00:00 • Commit: 4a9f867