解决冲突
若要继续推送我们刚做的修改到远程存储库,我们就必须手动解决冲突。为此,让我们执行拉取以从远程存储库获取最新的更改集。
单击工具栏菜单上的“Pull”。
![Execute pull](/static/8cb13eabeaba7cf21b192cf11f954e76/5a190/01.png)
单击“OK”。
![Click OK button](/static/b9202f3f226f6a8844542487a9cfb84c/5a190/02.png)
将弹出一个对话框警告我们合并冲突。关闭它,然后单击“Cancel”以取消拉取。
Git 无法完成拉取,因为它无法自动合并有冲突的文件。远程分支中的最新更改已下载到您的计算机,但您的工作树尚未更新。若要完成拉取,您必须先解决冲突。
选择本地分支中的最新提交,然后单击“Merge”。然后“OK”。
![click Merge then OK](/static/9673710ed8d1b0d4a05e9ac91c6b4622/5a190/03.png)
Sourcetree 将通知您存在合并冲突。单击“OK”。
![Conflict occurred during the merge](/static/955542a40e270a4d57af9878e1a0b062/5a190/04.png)
现在当您打开tutorial
文件夹中的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
一旦我们解决了冲突,并且文件的内容发生变化后,我们将需要启动提交。
选择“Uncommitted changes”并选择“Commit”。
我们现在更新了来自远程存储库的最新更改。
![Completed acquiring the latest changes from the remote repository](/static/a54e2d7026e57f01a5153b4f00c28f1a/5a190/05.png)
这表明这两个历史记录已成功与新的合并提交合并了。 我们现在可以安全地将此更改推送到远程存储库,而不会发生任何合并冲突。
如果您接下来不想学习在 Command Line 上使用 Git,请直接前往分支的章节。