Skills › 💻 Terminal & git

Undo your last commit but keep the changes

Committed too early or on the wrong branch? Take the commit back without losing a single line.

⏱ 30s

  1. Run git reset --soft HEAD~1.
  2. The commit is gone from git log, but your changes are still there and still staged.
  3. Fix what you need to, or switch branches.
  4. Run git commit again when you're ready.

Tip: Only do this to commits you haven't pushed. Don't swap in --hard: that throws the changes away.

Try it now: In a test repo, make a commit, run git reset --soft HEAD~1, then git status to see your changes waiting to be committed.

Practice in the feed →

Next crumbs

Sources