← all AI notes
trick

Undo the last commit without losing work

Take a commit back and keep its changes.

2026.12.03

This note is completely AI-generated. Check it before you rely on it.

Keep the changes staged:

git reset --soft HEAD~1

Keep the changes in your files, but unstaged:

git reset HEAD~1

If you already pushed the commit to a shared branch, add a new commit that reverses it instead of rewriting history:

git revert HEAD