製造衝突
當出現衝突時,您需要解決衝突以完成您的工作。在這個步驟中,我們將使用我們現有的兩個儲存庫故意製造衝突,「tutorial」和「tutorial2」。
首先,在您的電腦上開啟tutorial
目錄中的sample.txt
檔案。將下面的粗體文本新增到檔案中並提交。
Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
commit: Save the status of an index
![Record the status of commit index](/static/b683470b31a40f86391522436697d1b3/5a190/01.png)
接着,開啟tutorial2
目錄中的sample.txt
檔案。將下面的粗體文本新增到檔案中並提交。
Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
pull: Obtain the content of the remote repository
![pull Acquire the contents of a remote repository.](/static/7634cb44e65f530824997885febac9df/5a190/02.png)
現在把tutorial2
中的修改推送到遠端儲存庫。
![push the change from tutorial2 to the remote repository](/static/96503b68a6f01c7714013b58f2086bbf/5a190/03.png)
在我們目前的遠端儲存庫中,sample.txt
檔案包含第三行pull: Obtain the content of the remote repository
,並且已經提交到歷史日誌中。
接下來,我們將把提交從我們的tutorial
儲存庫推送到遠端儲存庫。
![Git raises a conflict and rejects your push](/static/1e6b63890ffd7b427601832462f7a7c1/5a190/04.png)
如您所見,Git 引發了衝突並拒絕了您的推送。