markmcdermott.io (js, ruby, ...etc) by mark mcdermott

Git: Undo Last Commit

git reset HEAD~

11/14/2024

read time:1 min

Yesterday I ran into an issue where I committed some changes locally in git and then wished I hadn’t. And I realized my last post about git, my Git Cheatsheet, didn’t have how to undo the last local commit. Turns out it’s one of the easiest things to do in git: git reset HEAD~. It just works. All files committed in the last commit will now show as unstaged with modifications, just like they were before you committed.

Of course, nothing with git is ever this simple. git reset has soft, mixed and hard options. When we omit those options, it defaults to mixed, which means unstage changes made after the last commit. soft means unstage everything. hard means ignore everything, which of course is destructive.

Sources (accessed 11/14/24)