[英]Need help to understand merge conflict example
我正在關注一本書中的示例,該書沒有顯示解決合並沖突的步驟。 本教程中提到的本教程對我不起作用 - 在本地系統上模擬多個用戶/提交者因此,我甚至無法學習合並。
以下是從書中復制的步驟 -
現在打開空白的participants.txt
文件並在其中粘貼以下行:( 我在每個名稱前添加了一個連字符 )
Finance team
Charles
Lisa
John
Stacy
Alexander
Git代碼 -
git init
git add .
git commit –m 'Initial list for finance team'
使用以下語法創建一個名為marketing的新分支:
git checkout –b marketing
現在打開participants.txt
文件並開始輸入財務團隊列表下方營銷部門的名稱,如下所示:( 我在每個名稱前添加了一個連字符 )
Marketing team
Collins
Linda
Patricia
Morgan
Git代碼 -
git add .
git commit –m 'Unfinished list of marketing team'
git checkout master
打開文件並刪除名稱Alexander和Stacy,保存,關閉,添加更改,並使用財務團隊的提交消息最終列表進行提交。
git add .
git commit –m "Final list from Finance team"
git checkout marketing
打開文件並為營銷團隊添加第五個名稱Amanda,保存,添加和提交。
git add .
git commit –m "Initial list of marketing team"
說已經確認輸入用於營銷的相同名稱; 現在我們需要合並這兩個列表,這可以通過以下命令完成。
git merge master
您將收到合並沖突,如以下屏幕截圖所示。 解決它們。
Auto-merging participants.txt
CONFLICT (content): Merge conflict in participants.txt
Automatic merge failed; fix conflicts and then commit the result.
我該如何解決這些沖突?
文件中的文字如下 -
Finance team
-Charles
-Lisa
-John
<<<<<<< HEAD
-Stacy
-Alexander
Marketing team
- Collins
- Linda
- Patricia
- Morgan
- Amanda
=======
>>>>>>> master
那些是合並標記:
<<<<<<<
Changes made on the branch that is being merged into. In most cases,
this is the branch that I have currently checked out (i.e. HEAD).
|||||||
The common ancestor version.
=======
Changes made on the branch that is being merged in. This is often a
feature/topic branch.
>>>>>>>
如“ 在Git中修復合並沖突? ”中所述,您應該:
或者您可以簡單地簽出這些文件以保留原始版本,如“ 我如何丟棄遠程更改並將文件標記為”已解決“? ”。
如您所見,您從marketing
部門( Stacy
和Alexander
)的Finance Team
中刪除的名稱又回來了。
所以當你把master
合並到marketing
,git會問你:決定,我們應該保留這些名字還是刪除它們?
正如Charles Bailey 在評論中補充的那樣 ,似乎缺少(基礎)共同祖先部分:
|||||||
The common ancestor version.
=======
你應該用配置重做exercice:
git config merge.conflictStyle diff3
這將有助於可視化三向合並的基本部分。
另請參閱“ 為什么3向合並優於雙向合並? ”。
OP 補充道
在確定要保留在文本文件中的內容並刪除合並標記
<<<HEAD
和>>>master
,需要使用git add [filename]
到舞台,然后正常提交。
你不能馬上執行git merge master
。
再次合並時,OP會報告錯誤消息:
error: 'merge' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm <file>' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: Exiting because of an unresolved conflict.
這是解決方案
git add .
git commit - m "success"
git merge master
請參閱“ GIT合並錯誤”提交是不可能的,因為您有未合並的文件“ ”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.