Git合并并保持独立?

Mid*_*ing 23 git

有没有办法用另一个(主人或其他人)的信息更新一个侧支,然后继续这两个?像一个rebase,但保留旧数据?

原版的:

A---B---C---G---H  master
     \           
      D---E---F  branchA
Run Code Online (Sandbox Code Playgroud)

结果:

A---B---C---G---H---L  master
     \           \
      D---E---F---J---K  branchA
Run Code Online (Sandbox Code Playgroud)

这样branchA从提交C,G和H获取信息(提交J就是合并),这样提交K仍然是一个侧分支(并且将来提交L仍然在主服务器上),但是具有来自主服务器的更新信息?

我不想做一个rebase,因为那最终会:

A---B---C---G---H---L  master
                 \
                  D'---E'---F'---K  branchA
Run Code Online (Sandbox Code Playgroud)

创建D,E和F的"新版本",好像它们发生在H而不是B之上,问题是提交C和E是重命名中的密钥文件夹的重命名,我想要折叠它们一起,还没有合并其他功能更新branchA.重新定位意味着H使用新文件夹名称,D'创建旧文件夹名称,E'再次删除它,这不是最干净的.

关键是我想要在过去重命名该文件夹(C和E)并停止向前推进.这有道理吗?我向后看这个吗?或者我应该只处理凌乱的rebase"名称,重命名"技巧,直到分支合并为止?

cdh*_*wie 21

如果您的历史记录在master上为H或L,在branchA上为F(即J和K尚不存在),则是,只需检查分支A并合并:

git checkout branchA
git merge H   # Use H's commit identifier if it's not the tip of master
Run Code Online (Sandbox Code Playgroud)

这会将更改合并到branchA中,并且根本不会干扰主分支.

如果您已经创建了commit K并且想要在它和F之间插入合并,那么还有一些工作要做:

git checkout -b temp F   # Create a new branch at commit F
git merge H              # Merge from commit H into the new branch
git cherry-pick K        # Apply the K commit to the merged commit

# And the rest simply replaces the temp branch with branchA
git checkout branchA
git reset --hard temp
git branch -d temp
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,如果您稍后在任一方向上合并,则提交H将是两个历史分支的最近共同祖先,因此在决定如何合并时,未来的合并将不会超过此提交(或过去J到F).