2011-01-30 70 views
1
  • 在分支之间进行简单合并会产生不需要的代码。
  • 樱桃采摘没有帮助,因为相关的代码溢出了多次提交
  • rebase?不知道它
+2

将相关代码拆分为多个提交不会导致樱桃采摘无用。你只需要挑选多个提交,可能使用-n。单个提交包含太多代码会更糟糕。 – 2011-01-30 11:36:09

回答

2

对于一组共同文件中的两个分支之间的真正共同的,一个解决方案确实变基(合并前),但假设:

  • 你还没有推你的分支到远程回购(因为你是即将改变历史)
  • 你有共同的集一些本地化提交文件的所有修改(换言之,提交同时包含特定主题一些常见的修改)

如果您的提交已被很好地标识为“通用”或“特定主题”,那么您可以更改它们的顺序,使得通用代码具有最新的分支提交。

从那里,这很容易:

  • 重订这些提交到“共同”分支
  • 合并回到你的当前主题的分支,分支(N为了找回所有这些变化)
  • 合并相同的“共同”分支到其他“标题2”分支(它也具有相同的共同演进)

git: how do I merge between branches while keeping some changesets exclusive to one branch?

t1a--t1b--ca--cb--t1c # topic1 with some common commits in it 'ca' and cb' 
t2a--t2b    # second topic branch 

rebase --interactivetopic1分支:

t1a--t1b--t1c'--ca'--cb' # topic1 with some common commits in most recent position 
t2a--t2b    # second topic branch 

rebase --onto(或者干脆复位topic1checkout -b commonHEAD,如果common分支还不存在),如秀 “merge between branches while keeping some changesets exclusive to one branch?

t1a--t1b--t1c' # topic1 without any common code 
ca''--cb''  # common branch 
t2a--t2b  # second topic branch 

合并两个主题分支中的常见更改:

t1a--t1b--t1c'--c1 # topic1 with a commit with common code evolutions 
ca''--cb''   # common branch 
t2a--t2b--c1'  # second topic branch with same common code evolutions 
+0

通常情况下,最好提供一般的提交,而不是_rebase_它们。但是,有时候交互式底版可能会有用...... – 2011-06-08 17:05:04