簡體   English   中英

Git,合並分支git

[英]Git, merging branches git

我不明白為什么我的合並會更新一個提交...看起來它正在更新提交添加顏色,而不是將母版與硬幣合並。 當我嘗試合並這些分支時,Sublime不會彈出。 有人可以幫助我嗎? 此外,當我輸入git commit時,我有:

在分支母版上您的分支比“原始/母版”提前2次提交。 (使用“ git push”發布您的本地提交)無任何提交,工作樹干凈

在此處輸入圖片說明

我不確定您的問題是什么,但是您可能無法完全理解這里發生的兩件事。

首先,我認為git merge master coins並沒有您認為的那樣。

git merge master coins 並沒有說將master合並成coins 它說將master coins合並到當前簽出的分支中。 這是因為master coins是要合並到當前分支中的分支的列表。 從文檔 ...

[git merge]將命名提交的更改(自其歷史記錄與當前分支分開以來的時間) 合並到當前分支中

如果檢出了master ,則它將硬幣合並到母版中。 如果檢出了coins ,則它將master合並為coins 如果簽出了其他內容,您將得到所謂的“章魚合並”,並且mastercoins和當前分支這三個都合並在一起,可能是一團糟。

就目前而言,您已與已檢出的master合並,因此git merge master coinsgit merge coins相同。 您將coins合並master ,我想這是您想要的,但是它可能變糟了。

因此,請勿使用該語法。 它會給您帶來麻煩,並且通過查看命令歷史記錄很難知道實際發生了什么。 而是使用git checkout branch-to-merge-into; git merge branch-to-merge-from git checkout branch-to-merge-into; git merge branch-to-merge-from 因此,如果要將硬幣合並成master,請使用git checkout master; git merge coins git checkout master; git merge coins


下一個問題是關於快進合並。 當不需要合並時,分支沒有分歧時,Git會執行此操作。 例如,假設您有這個...

A - B - C - D - G [master]
         \
          E - F - H [feature]

由於master具有與feature (D和G)不同的更改,因此必須合並。 所以git checkout master; git merge feature git checkout master; git merge feature導致新的合並提交。

A - B - C - D - G - I [master]
         \         /
          E - F - H [feature]

但是,如果master上沒有新的提交,則可以使用它( master指向C)。

         [master]
A - B - C - E - F - H [feature]

據說feature上沒有與master背道而馳。 不需要合並提交,因此Git不會打擾任何人。 當你做git checkout master; git merge feature git checkout master; git merge feature ,只需將master移至H。

                      [master]
A - B - C - E - F - H [feature]

Git之所以可以這樣做是因為“分支”實際上只是指向提交的標簽。 現在, masterfeature指向同一提交。


我建議在合並要素分支時避免快進,因為它會丟失重要的考古信息。 稍后查看存儲庫的人無法分辨E,F和H都是作為單個分支完成的。

我建議始終將功能分支與git merge --no-ff 這迫使Git進行合並提交,將來嘗試弄清楚您的代碼的人可以知道E,F和H都是更大整體的一部分。

A - B - C --------- I [master]
         \         /
          E - F - H [feature]

合並提交I還為您提供了一個描述分支的地方,並添加了指向問題/錯誤/票證的鏈接之類的內容,以描述分支的用途。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM