http://stackoverflow.com/questions/2938301/remove-specific-commit
There are four ways of doing so:
-
Clean way, reverting but keep in log the revert:
git revert --strategy resolve <commit>
-
Harsh way, remove altogether only the last commit:
git reset --soft "HEAD^"
-
Rebase (show the log of the last 5 commits and delete the lines you don't want, or reorder, or squash multiple commits in one, or do anything else you want, this is a very versatile tool):
git rebase -i HEAD~5
And if a mistake is done:
git rebase --abort
-
Quick rebase: remove only a specific commit using its id:
git rebase --onto commit-id^ commit-id
-
Alternatives: you could also try:
git cherry-pick commit-id
Another alternative:
git revert --no-commit
Note: of course, all these changes are done locally, you should git push
afterwards to apply the changes to the remote. And in case your repo doesn't want to remove the commit ("no fast-forward allowed", which happens when you want to remove a commit you already pushed), you can use git push -f
to force push the changes.