Created
May 22, 2025 16:26
-
-
Save christophermark/9f9706cd1620aa7d0f9cd990f3febecf to your computer and use it in GitHub Desktop.
Git reset but keep commit message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. Prevent losing the message in the first place | |
| If you know ahead of time that you want to “undo” a commit without losing either your changes or your commit message, use soft reset: | |
| # Move HEAD one commit back, but keep index & working-tree untouched | |
| git reset --soft HEAD~1 | |
| • What it does | |
| • HEAD moves to the previous commit | |
| • Your index (staging area) still contains exactly what you had in that commit | |
| • Your working tree is untouched | |
| At this point you can simply re-commit, reusing the old message: | |
| # Re-commit, copying the original commit message: | |
| git commit -c ORIG_HEAD | |
| Here, ORIG_HEAD is the ref Git automatically sets to the pre-reset HEAD. The -C <commit> flag tells Git “reuse that commit’s message exactly.” |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment