Removing a specific commit in the git history with several branches?

江枫思渺然 提交于 2019-12-22 20:44:05

问题


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?


回答1:


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'


来源:https://stackoverflow.com/questions/21427060/removing-a-specific-commit-in-the-git-history-with-several-branches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!