Skip to content

Instantly share code, notes, and snippets.

@ejhayes
Created May 30, 2013 22:56
Show Gist options
  • Save ejhayes/5681927 to your computer and use it in GitHub Desktop.
Save ejhayes/5681927 to your computer and use it in GitHub Desktop.
Git commit rollback. I have a repository that has some previous commits that I now want to roll back. My commit history looks like this: A -> B -> C -> D -> E -> F -> G I just committed to G, but realized that commits C and D should never have been made. How can I roll this back?
#!/bin/bash
$ git log --oneline
066087b Adding new support.
3f21325 removing the test file
a4cde53 updating a file again
a86af8a updating a file
cdec8c0 testing a git commit
c25db10 added assets
2554c74 made header text a link
...
# I need to remove c25db10 (D) and 2554c74 (C) commits. Mathematically we know that
# (CD)^-1 = D^1 C^-1, therefore we must revert D then revert C. We also want to do this
# whole revert as a single commit
git revert c25db10 --no-commit
git revert 2554c74 --no-commit
git commit -m "Reverted previous commits D and C since we have now identified that they broke our current code"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment