解決衝突
若要繼續推送我們剛做的修改到遠端儲存庫,我們就必須手動解決衝突。為此,讓我們執行拉取,以從遠端儲存庫獲取最新的變更集。
右鍵單擊「tutorial」目錄,然後選取「Pull」。
![Click Pull from right-click menu.](/static/0c1eb8c122714feda1c86b86dbe0de73/5a190/01.png)
單擊「OK」。
![Click OK button](/static/9044d241db7114bf696d0917fbed2da1/5a190/02.png)
如果您看到一個教您合併的訊息方塊,請閱讀它並單擊「OK」。
![The message automatic merge failed comes up](/static/2cc67062ba0afa71e804840fbd15cf29/5a190/03.png)
當您看到自動合併失敗的警告訊息時,單擊「Close」。
![Click Close button](/static/baf360f2230224498193aabfdbe8be4f/5a190/04.png)
然後系統會詢問您是否要查看此修訂版中的更改。單擊「Yes」。
![Click Yes button](/static/0bbe94c3fbdef013f463239c96ce67df/5a190/05.png)
TortoiseGit 告訴我們自動合併失敗,因為「sample.txt」有合併衝突。單擊「OK」。
![The conflicts have happened.](/static/5e902757659a20976bed352be96f0487/5a190/06.png)
當您開啟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」。
![A window about merges](/static/d53d7dc48f94c80bb7ce206b6cdf72e8/5a190/07.png)
右鍵單擊範例檔案,並選取「Resolved」,因為我們剛才使用我們的文本編輯器手動解決了這個合併衝突。
![Right-click the sample file and choose Resolved](/static/65330c3fd30a30c15df64c1d78e57afe/5a190/08.png)
當顯示確認此更改的視窗時,單擊「Yes」。
![a window displays to confirm this change](/static/c5975c792bf57a881a9d60c1d60bfa00/5a190/09.png)
當被警告提交訊息仍然提到衝突的檔案時,選取「Ignore」或「Abort」。然後從提交訊息中移除這些行,或者按照底部的建議,讓 TortoiseGit 自動為您移除以「#」開頭的行。(自動移除這些行是大多數其他 Git 客戶端的預設行為)。
我們現在更新了來自遠端儲存庫的最新更改。
![Completed acquiring the latest changes from the remote repository](/static/43ea2017d67169e54487b2ae2616c92f/5a190/10.png)
這表示這兩個歷史紀錄已成功與新的合併提交合併了。 我們現在可以安全地將此更改推送到遠端儲存庫,而不會發生任何合併衝突。
如果您接下來不想學習在 Mac 或 Command Line 上使用 Git,請直接前往分支的章節。