如何更新startpoint以替换合并提交

时间:2017-10-01 22:51:36

标签: git git-svn branching-and-merging

我们想将svn存储库转换为git。现在我想在转换的分支上做一些清理工作:

A1-A2-A3--A6-A7-----A11-A12-An
    \      \            /
     `------B1-B2---B25´

B1是一个合并提交,用于将更改A3导入A7到分支B.更好的方法可能是从A7开始并删除合并提交B1。

A1--A6-A7-A8-A9----A12-An
         \         /
          `B2--B25´

我已尝试将分支B转换为A,但结果已经相同。

更新 作为上游的missundertsanding,A上没有跟踪的远程分支。 (svn分支和标签已被删除)。

我已经更新了标题

2 个答案:

答案 0 :(得分:0)

我认为你正走在正确的道路上。请尝试以下操作将您的更改从B分支重新绑定到A分支的顶端:

git checkout A
git pull
git checkout B
git pull
git rebase A
<fix conflicts>
git push -f

答案 1 :(得分:0)

一个技巧点:如果您编辑历史记录,将创建新的提交(它们将具有新的哈希值,如果您的当前历史记录已经与其他开发人员共享,则必须告诉他们强制更新其回购)。

我将描述一种改造方式:

# this :
A1-A2-A3--A6-A7-----A11-A12-An
    \      \            /
     `------B1-B2---B25´

# into this :
A1--A6-A7-A8-A9---A11-A'12-A'n
         \           /
          `B'2--B'25´

B分支上的提交将是新的提交,以及A分支上的提交,从merge in B提交开始。

对于初学者,我建议在临时分支机构工作:

# create branch 'wipB' on commit B25 and switch to this new branch :
git checkout -b wipB B25
  1. 如果您想在B2, ..., B25之上重播A7,可以使用
    git rebase --onto <new_base> <upstream> <branch>
    git rebasedoc here)的变体:

    # note the `B1` : the commit mentionned as <upstream> is ommitted
    git rebase --onto A7 B1 wipB
    
  2. 重新创建合并提交A12

    # start a new "A" branch from A11 :
    git checkout -b wipA A11
    
    # merge the new "B" branch :
    git merge wipB
    
    # once merge is resolved, you can compare with the original A12 to see
    # if this new merge commit has all the content you expect :
    git difftool -d wipA A12
    
  3. A13, .., An之上重播A'12

    git rebase --onto wipA A12 An
    
相关问题