Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. 如何使用 Git
  6. 如何在 Mac 中使用 Git
  7. 解决冲突
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

解决冲突

若要继续推送我们刚做的修改到远程存储库,我们就必须手动解决冲突。为此,让我们执行拉取以从远程存储库获取最新的更改集。

单击工具栏菜单上的“Pull”。

Execute pull

单击“OK”。

Click OK button

将弹出一个对话框警告我们合并冲突。关闭它,然后单击“Cancel”以取消拉取。

Git 无法完成拉取,因为它无法自动合并有冲突的文件。远程分支中的最新更改已下载到您的计算机,但您的工作树尚未更新。若要完成拉取,您必须先解决冲突。

选择本地分支中的最新提交,然后单击“Merge”。然后“OK”。

click Merge then OK

Sourcetree 将通知您存在合并冲突。单击“OK”。

Conflict occurred during the merge

现在当您打开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

这表明这两个历史记录已成功与新的合并提交合并了。 我们现在可以安全地将此更改推送到远程存储库,而不会发生任何合并冲突。

如果您接下来不想学习在 Command Line 上使用 Git,请直接前往分支的章节

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life