Brent Keller

Undo last commits

You can easily "undo" the past n commits in your local git branch using the reset command. This reset action removes the commits from the history and places all of the changes from the commits in an unstaged status. I use this often to recompose commits so I can organize my work in sensible chunks.

Note: This is not the same as reverting commits

Warning! This should not be done if the commits you're about to undo have been pushed to a remote!

# Undo the most recent commit
git reset head~

# Undo the last 3 commits
git reset head~3

Learn more from the git documentation

© 2023 Brent Keller