删除具有多个分支的git历史记录中的特定提交? [英] Removing a specific commit in the git history with several branches?

查看:120
本文介绍了删除具有多个分支的git历史记录中的特定提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用 git rebase --interactive 从git历史记录中删除特定的提交。

我的问题涉及这样一个更复杂的案例:

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

我想删除提交 X 。问题是在这种情况下,有两个或两个以上的家长分支(在这种情况下 B )有 X 在他们的历史中,所以一个单一的 git rebase -i 并不会这样做(至少我不知道如何)。

是否有一种简单的方法可以删除 X ,或者我必须依赖自己绑定所有分支,可能使用shell脚本?

解决方案

不幸的是Git在这种情况下并不容易。首先通过删除提交X来在D分支上进行交互式分配。



您将获得以下历史记录:

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

然后您需要将F分支重新绑定到B'上:

  git rebase --onto B'BF 

(用他们的id替换提交名称)



这将以

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


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'

这篇关于删除具有多个分支的git历史记录中的特定提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆