解決衝突
若要繼續推送我們剛做的修改到遠端儲存庫,我們就必須手動解決衝突。為此,讓我們執行拉取,以從遠端儲存庫獲取最新的變更集。
右鍵單擊「tutorial」目錄,然後選取「Pull」。

單擊「OK」。

如果您看到一個教您合併的訊息方塊,請閱讀它並單擊「OK」。

當您看到自動合併失敗的警告訊息時,單擊「Close」。

然後系統會詢問您是否要查看此修訂版中的更改。單擊「Yes」。

TortoiseGit 告訴我們自動合併失敗,因為「sample.txt」有合併衝突。單擊「OK」。

當您開啟sample.txt
時,您會看到 Git 新增的標記表明該檔案章節存在衝突,如下所示。
Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
<<<<<<< HEAD
commit: Save the status of an index
=======
pull: Obtain the content of the remote repository
>>>>>>> 17c860612953c0f9d88f313c8dfbf7d858e02e91
我們將透過接受兩個更改,並移除標記來解決衝突。
Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
commit: Save the status of an index
pull: Obtain the content of the remote repository
一旦我們解決了衝突,並且檔案的內容發生變化後,我們將需要啟動提交。
右鍵單擊並選取Git Commit -> 'main'
。
將顯示一個關於合併的視窗;單擊「OK」。

右鍵單擊範例檔案,並選取「Resolved」,因為我們剛才使用我們的文本編輯器手動解決了這個合併衝突。

當顯示確認此更改的視窗時,單擊「Yes」。

當被警告提交訊息仍然提到衝突的檔案時,選取「Ignore」或「Abort」。然後從提交訊息中移除這些行,或者按照底部的建議,讓 TortoiseGit 自動為您移除以「#」開頭的行。(自動移除這些行是大多數其他 Git 客戶端的預設行為)。
我們現在更新了來自遠端儲存庫的最新更改。

這表示這兩個歷史紀錄已成功與新的合併提交合併了。 我們現在可以安全地將此更改推送到遠端儲存庫,而不會發生任何合併衝突。
如果您接下來不想學習在 Mac 或 Command Line 上使用 Git,請直接前往分支的章節。