gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
what is the correct command to revert one commit: git revert ~HEAD-1
- User
what is the correct command to revert one commit: git revert ~HEAD-1
- Assistant
The command you wrote,
git revert ~HEAD-1, is not correct syntax for reverting a commit.If you want to revert the commit just before the current
HEAD(i.e., the one commit before the current commit), you would use:bashgit revert HEAD~1Explanation:
HEADrefers to the current commit.HEAD~1refers to the parent of the current commit (one commit beforeHEAD).git revert <commit>creates a new commit that undoes the changes introduced by the specified commit.
Summary:
- To revert the last commit:
bash
git revert HEAD - To revert the commit before the last commit:
bash
git revert HEAD~1
Your command had the tilde
~in front ofHEAD, which is invalid syntax. It should beHEAD~1without the space or extra symbols.