解决 git pull 合并冲突
对于 git pull (以及扩展的 git merge)引发合并冲突,本地和远程存储库必须不同步,这是否正确?基本上,是否有必要满足这两个条件才能发生合并冲突 -
- 必须至少有一个本地提交尚未推送到远程。
- 必须至少有一项在远程提交(尚未拉取)涉及更改与本地提交之一(尚未推送)相同的代码行。
Is it correct that for git pull (and thus git merge by extension) to throw merge conflicts, the local and remote repositories have to be out of sync ? Basically, is it necessary for these 2 conditions to be met in order to get a merge conflict -
- There must be at least one commit made locally that hasn't been pushed to remote.
- There must be at least one commit made on remote (that hasn't been pulled yet) that involves the changing the same line of code as one of the commits made locally (that hasn't been pushed yet).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
非常正确。
至于合并:当然,你这边必须有一个远程没有的提交;否则我们会快进,这并不是真正的合并。并且遥控器上必须有一个您没有的提交:否则什么也不会发生(您将是最新的)。
但这仅仅是实现合并的先决条件。
至于合并冲突:不一定是同一行代码,也可以是相邻行。还有其他方法会导致合并冲突,例如一侧完全删除文件。
然而,重要的不是“本地做出的承诺之一”。这是自上次共同提交以来双方所做工作的总体。如果您有一个提交编辑了他编辑的同一行,然后您有另一个提交将其再次更改回或更改为他所拥有的内容,则不会发生冲突。
Pretty much correct.
As for the merge: Certainly there must be a commit on your side that the remote doesn't have; otherwise we'd fast forward, which is not really a merge. And there must be a commit on the remote that you don't have: otherwise nothing would happen (you'd be up to date).
But that is merely the prerequisite to get a merge in the first place.
As for the merge conflict: It doesn't have to be the same line of code, it could be an adjacent line. And there are other ways to get a merge conflict, like one side deletes the file entirely.
What matters, however, is not "one of the commits made locally". It is the totality of what has been done on each side since the last common commit. If you had a commit that edited the same line he edited, and then you had another commit that changed it back again or changed it to what he has, there is no conflict.
是的,两个存储库都必须至少有一个更改相同行的不同步提交。否则,远程分支中的最新更改将传输到本地克隆,而不会发生冲突。
Yes, both repos must have at least one unsynchronized commit each that changes the same lines. Otherwise, the most up-to-date change in the remote branch will be transferred to the local clone without a conflict.