![](/img/trans.png)
[英]<GIT> I have branched off a branch and want to push my changes. Do I push changes to the original branch or merge the two branches?
[英]Accidentally branched off of the wrong branch, and when I want to merge into the master I have to merge both branches
所以我創建了一個我已經創建的另一個分支的分支,現在當我嘗試將分支合並到master時,我遇到了必須合並兩個分支的情況。
這是一張圖
主 - >
->Branch 1 -> Branch 2
我希望能夠將分支2上的更改僅合並到master上,而不必合並分支1上的更改(如果有意義的話)。 我查看了重置並恢復,但似乎這些東西將刪除我用分支2做的所有更改。任何想法?
謝謝
使用以下語法嘗試git rebase --onto:
將branch2的更改放在master上而不包括branch1
git rebase --onto master branch1 branch2
git help rebase
相關輸出git help rebase
:
以下是如何使用
rebase --onto
將基於一個分支的主題分支移植到另一個分支,假裝您從后一個分支分叉主題分支。首先,讓我們假設你的主題是基於分支旁邊 。 例如, 主題中開發的功能取決於下一步中的某些功能。
o---o---o---o---o master \\ o---o---o---o---o next \\ o---o---o topic
我們想要從分支主人分叉主題 ; 例如,因為主題所依賴的功能被合並到更穩定的主分支中。 我們希望我們的樹看起來像這樣:
o---o---o---o---o master | \\ | o'--o'--o' topic \\ o---o---o---o---o next
我們可以使用以下命令獲取此信息:
git rebase --onto master next topic
請記住這里提到的變革風險和陷阱: http : //git-scm.com/book/en/Git-Branching-Rebasing
一種方法是使用cherry-pick
。 做一個git log branch2
並找到你想要的提交id,然后使用git checkout master
切換到master
分支然后使用git cherry-pick <commit_id>
有關詳細信息,請參閱此帖子
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.