How to Undo Git Amend
Publish date: Mar 28, 2023
Last updated: Mar 30, 2023
Last updated: Mar 30, 2023
1. Find the old commit
git log --reflog --oneline
052047f (HEAD -> main) Create how-to-undo-git-amend post
d4012dd Create how-to-undo-git-amend post
Here the old commit is d4012dd
.
2. Move the current head to the old commit
git reset --soft d4012dd
The --soft
flag uncommits the most recent commit, while keeping the changes in the staging area.
3. Create new commit
git commit -m "New commit"