Skip to content

Instantly share code, notes, and snippets.

@hermanschaaf
Created October 7, 2019 08:08
Show Gist options
  • Save hermanschaaf/02eae4ddb024a46ca94bcbd61066059a to your computer and use it in GitHub Desktop.
Save hermanschaaf/02eae4ddb024a46ca94bcbd61066059a to your computer and use it in GitHub Desktop.
Revert back to a specific commit

So you want to create a revert commit for a lot of commits, and git revert HEAD~10..HEAD isn't working because there are merge commits in between? Here's a workaround using a patch file:

git checkout master
git pull origin master
git log --oneline # find the hash of the commit you want to revert to
git checkout <hash>
git checkout -b my-revert-branch
git diff master > mypatch.patch
git checkout master
git branch -D my-revert-branch
git checkout -b my-revert-branch
git apply mypatch.patch
rm mypatch.patch
git add -A .
git commit -m "Revert changes"
git push origin my-revert-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment