Live streamJoin us for "State of code review 2024" on July 18thRegister today

How to uncommit in git?

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Made a mistake in your commit? No worries! Git's flexible nature lets you rewind the tape, allowing you to correct, adjust, or simply reminisce about your code.

git reset HEAD~1

This command moves the HEAD and the current branch pointer to the previous commit, without changing the working directory.

  • Use git reset HEAD~1 to move one step back in your project's timeline. This nudges the current branch pointer back to the previous commit, leaving your changes in the working directory.
  • Opt for git reset --soft HEAD~1 if you wish to uncommit but keep the changes staged, ready for a fresh commit.
  • If you're looking to scrap your last commit entirely (changes and all), use git reset --hard HEAD~1.

Picture your project as a movie reel. Each commit is a frame in your story. Uncommitting simply rewinds the reel, letting you reshoot the scene or even rewrite the script.

  • Unsure about which reset mode to choose? Remember:

    • --soft: Keep your changes staged.

    • --mixed (default): Unstage your changes, but keep them in your working directory.

    • --hard: Discard the changes entirely.

  • Use git reflog to see a history of where HEAD has pointed, making it easier to navigate or even recover from more complex mistakes.


Keep in mind that with great power comes great responsibility. Uncommitting is a powerful tool, but always be cautious, especially when collaborating with others. Happy coding! 🌠

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2