Undo Git Commit amend
How to Undo “git commit –amend”
1
git reset --soft HEAD@{1}
Using the Git amend command (git commit –amend), we can change the message of a commit or even its content. But when we amend (or modify) something, it becomes a new thing, right? Therefore, when we change the message or content of a Git commit, the original commit is replaced by a new commit containing the changes.
Actually, after a Git amendment, we’ll still have just one commit containing all our combined content, but with a different hash. In practice, Git makes the old commit private and creates a new public one.
This is great news, as it means we can completely undo the effects of a Git amendment. However, we need to know how to reference the old commit properly so that we can undo the amendments.
we can consult the detailed history of commits via the Git reflog:
1 2 3 4 $ git reflog 3499867 (HEAD -> feature1) HEAD@{0}: commit (amend): My updated commit message 400071c HEAD@{1}: commit: My original commit message ...