How can set an older commit to be HEAD?

Here is what you can do:

git checkout <branch-to-modify-head>
git reset --hard <commit-hash-id-to-put-as-head>
git push -f

If you don’t force the push, git will throw this error: Updates were rejected because the tip of your current branch is behind.

Note that this will tamper your git history, so another way of doing this is revert each commit you don’t want. That way you retain your history:

git revert commit-id


Leave a Comment