سؤال

I know how to remove a specific commit from the git history with git rebase --interactive.

My question concerns the more complex case with a history like this:

A--X--B--C--D
       \
         E--F

where I would like to remove the commit X. The issue is that in this case there are two or more branches with parents (B in this case) that have X in their history, so a single git rebase -i will not do the trick (at least I do not know how).

Is there a simple way to remove X, or do I have to rely on rebasing all branches on their own, possibly with a shell script?

هل كانت مفيدة؟

المحلول

Unfortunately Git doesn't make it easy in this situation. First do an interactive rebase on the D branch by deleting commit X.

You'll have the following history:

A--X--B
 \     \
  \      E--F
   \
     B'-C'-D'

Then you'll need to rebase the F branch onto B' with:

git rebase --onto B' B F

(replace commits names by their ids)

That will end up with

 A--B'-C'-D'
     \
       E'--F'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top