简体   繁体   English

在远程合并了一个拉取请求后,将更改拉到本地分支时为什么会有冲突?

[英]Why are there conflicts when pulling changes to a local branch after a pull request has been merged at the remote?

From my develop branch I create a feature branch and make some changes. 从我的develop分支创建一个feature分支,并进行一些更改。 After all my changes have been made I squash all my commits so that only 1 commit message is added after the merge like so, git reset --soft HEAD~X & git commit & git push -f , where X is the number of commits to squash. 完成所有更改后,我git reset --soft HEAD~X & git commit & git push -f所有提交,以便在合并后仅添加1条提交消息,如下所示: git reset --soft HEAD~X & git commit & git push -f ,其中X是提交数壁球。

A pull request is then created and the feature is successfully merged into develop without any conflicts. 然后创建一个拉取请求,并且feature已成功合并到develop而没有任何冲突。 I then wish to update my local develop branch, so I do the following git checkout develop & git pull . 然后,我希望更新我的本地develop分支,因此执行以下git checkout develop & git pull

There are conflicts, why is this, and how might I avoid them? 有冲突,为什么会这样,又如何避免冲突?

Note that there have been no changes made to the local copy of develop in this scenario. 请注意,在这种情况下,没有对develop的本地副本进行任何更改。

There are conflicts, why is this, and how might I avoid them? 有冲突,为什么会这样,又如何避免冲突?

Someone else has committed code that cause it. 有人提交了导致它的代码。
In order to avoid it try to use pull request is you can, all major servers support it and you will see the conflicts before its being merged. 为了避免尝试使用pull request ,所有主要服务器都支持它,并且在合并之前会看到冲突。

The best way to handle it is to pull developer into your feature branch very frequently. 最好的处理方法是非常频繁地将developer拉入功能branch This will lower the possibility of having conflicts. 这将降低发生冲突的可能性。

If you wish to run "dry run" before merging you can this (depend what is your current checked-out branch) 如果您希望在合并之前运行“空运行”,则可以这样做(取决于您当前已签出的分支是什么)

git log ^branchA branchB

git log ^develop feature
git log develop ^feature

Usually it's fast forward pull as Mark said. 正如Mark所说,通常是快进。

If there has conflict, it's mainly caused the develop branch has been force changed (squash, rebase etc). 如果存在冲突,则主要是由于对develop分支进行了强制更改(压榨,变基等)。 Before you pull changes from remote develop branch to local devlop branch, you can check by below commands: 在将更改从远程develop分支拉至本地devlop分支之前,可以通过以下命令进行检查:

git fetch origin develop
git log develop..origin/develop --oneline
git log origin/develop..develop --oneline

If git log origin/develop..develop --oneline has output, that means the develop branch commit history has been changed by others. 如果git log origin/develop..develop --oneline已输出,则意味着他人已更改了develop分支的提交历史记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM