2012-08-30 38 views
1

假設我有分支A。現在我從A創建新分支B並進行一些提交。假設在這段時間內A也得到了一堆提交。有沒有辦法將這些新的提交合併到B,這樣我在B上提交的提交就會成爲頂級提交?如何合併分支以使新提交處於頂層?

舉例說明:

A -> a1 -> a2 -- B created here -- -> a3 -> a4 
       B -> a1 -> a2 -> b1 -> b2 

如何合併

B -> a1 -> a2 -> a3 -> a4 -> b1 -> b2 
+0

我覺得這是一個騙局。它看起來像一個標準的「rebase」問題。這有什麼別的嗎? –

回答

4

你想rebase這樣B結束一樣,不merge

B,做

git rebase A 

這不會影響A分支,但會重寫B分支的最近歷史記錄。

在此之前,你有

... -> a1 -> a2 -> a3 -> a4 -> A 
       \--> b1 -> b2 -> B 

後,你將有:

... -> a1 -> a2 -> a3 -> a4 -> A 
          \--> b1 -> b2 -> B 
1

使用git rebase

我的典型的工作流程,其中包括在分公司工作,並融入主人是:

git status # Make sure I am in the master branch, "git checkout master" if not 
git pull 
git checkout -b new_branch # New branch called new_branch 
# do the work, tests, etc. 
git add . 
git commit 
git checkout master 
git pull # Get the very latest master 
git checkout my_branch 
git rebase master 
git checkout master 
git merge my_branch 
git push master 
相關問題