解决冲突
若要继续推送我们刚做的修改到远程存储库,我们就必须手动解决冲突。为此,让我们执行拉取以从远程存储库获取最新的更改集。
右键单击“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,请直接前往分支的章节。