2011-01-30 68 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