git 快进合并是不可能的。要合并这个请求,首先在本地变基

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53066369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:13:44  来源:igfitidea点击:

Fast-forward merge is not possible. To merge this request, first rebase locally

gitgithubgitlabbranchrebase

提问by SanjX

Recently, I have created newbranch and created a merge request to Master branch. Before TeamLead accept merge request into Master branch another team member was committed another fix to the same branch(newbranch). After that I committed my local changes and pulled the changes in newbranch to local branch. And I pushed my local commit to newbranch

最近,我创建了 newbranch 并创建了一个到 Master 分支的合并请求。在 TeamLead 接受合并请求到 Master 分支之前,另一个团队成员向同一分支(新分支)提交了另一个修复程序。之后,我提交了我的本地更改并将 newbranch 中的更改拉到本地分支。我把我的本地提交推送到 newbranch

gitlab error

gitlab 错误

My TeamLead told me to rebase my branch to an earlier version. And resolve conflicts. I don't know what to do now. Any idea?

我的 TeamLead 告诉我将我的分支重新设置为早期版本。并解决冲突。我现在不知道该怎么办。任何的想法?

采纳答案by Tim Biegeleisen

It seems that your GitLab is configured to not allow feature branches with merge commits to be merged into the masterbranch. This is where you took a wrong turn:

似乎您的 GitLab 配置为不允许将具有合并提交的功能分支合并到master分支中。这是你走错路的地方:

After that I committed my local changes and pulled the changes in newbranch to local branch.

之后,我提交了我的本地更改并将 newbranch 中的更改拉到本地分支。

What you should have done is to commit your work, and then pull via rebase from the remote newbranchbranch. To remedy the situation, I suggest nuking the merge commit which happened when you pulled from GitLab. A merge commit is likely what happened, because git pullby default uses the merge strategy, not the rebase strategy. Check git log, and see how many commits were introduced due to the incorrect pull. Assuming there were only a single merge commit, then the following should do:

您应该做的是提交您的工作,然后通过 rebase 从远程newbranch分支中拉取。为了解决这种情况,我建议取消从 GitLab 拉取时发生的合并提交。合并提交可能是发生了什么,因为git pull默认情况下使用合并策略,而不是变基策略。检查git log,并查看由于不正确的拉取而引入了多少提交。假设只有一个合并提交,那么应该执行以下操作:

git reset --hard HEAD~1

Verify again that git loglooks correct. You should now see only your latest commit on the top of the branch. Assuming you do see this, then you are good to pull via rebase:

再次验证git log看起来正确。您现在应该只看到分支顶部的最新提交。假设您确实看到了这一点,那么您可以通过 rebase 拉取:

git pull --rebase origin newbranch

This will bring in your colleague's commit, then replay your latest commit on top of the branch. Finally, you may push the branch out, and the problem should be resolved:

这将引入您同事的提交,然后在分支顶部重放您的最新提交。最后可以push分支出来,问题应该解决了:

git push origin newbranch

Note that doing a hard reset as I have suggested above is generally not a good thing to do. But in your case, no one has seen that merge commit yet, because GitLab rejected your attempt to push. So you should be safe in removing it.

请注意,按照我上面的建议进行硬重置通常不是一件好事。但是在您的情况下,还没有人看到合并提交,因为 GitLab 拒绝了您的推送尝试。所以你应该安全地移除它。

回答by chevybow

Starting on your newBranch:

从你的 newBranch 开始:

git checkout masterto get back on the master branch

git checkout master回到主分支

git pull origin masterto get the most up-to-date version of the master branch

git pull origin master获取最新版本的主分支

git checkout newBranchto get back on your newBranch

git checkout newBranch回到你的新分支

git rebase origin/master -ito perform an interactive rebase. The command will take you through and let you pick commits, rename them, squash them, etc. Assuming you will want to keep them all, it will pause when there are merge conflicts and then you'll have to resolve them in your text editor, it will tell you where (in your text editor) that the conflicts occur. You will have to add those files after fixing them then do git rebase --continueto proceed with the rebase.

git rebase origin/master -i执行交互式变基。该命令将引导您完成并让您选择提交、重命名它们、压缩它们等。假设您想保留所有这些,它会在出现合并冲突时暂停,然后您必须在文本编辑器中解决它们,它会告诉您(在您的文本编辑器中)发生冲突的位置。您必须在修复这些文件后添加它们,然后git rebase --continue才能继续进行变基。

When you're done with the rebase your newBranch will be synced up with master and have any commits in master that weren't there when you started your work, and all merge conflicts will be resolved so that you can easily merge your newBranch.

完成 rebase 后,您的 newBranch 将与 master 同步,并且在 master 中有您开始工作时不存在的任何提交,并且所有合并冲突都将得到解决,以便您可以轻松合并 newBranch。