How do you remove a specific revision in the git history?
Suppose your git history looks like this:
1 2 3 4 5
1–5 are separate revisions. You need to remove 3 while still keeping 1, 2, 4 and 5. How can this be done?
Is there an efficient method when there are hundreds of revisions after the one to be deleted?
Per this comment (and I checked that this is true), rado's answer is very close but leaves git in a detached head state. Instead, remove HEAD
and use this to remove <commit-id>
from the branch you're on:
git rebase --onto <commit-id>^ <commit-id>
Here is a way to remove non-interactively a specific <commit-id>
, knowing only the <commit-id>
you would like to remove:
git rebase --onto <commit-id>^ <commit-id> HEAD