git rebase 合并冲突
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11709885/
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
git rebase merge conflict
提问by pahnin
I forked a github repo and worked on my github repo.
I have made pull-requests and it was completed.
我分叉了一个 github 存储库并在我的 github 存储库上工作。
我已经提出了拉取请求,并已完成。
After that the upstream had some more commits so now I want to rebase, I guess thats what I have to do.
But I'm getting these merge conflicts:
在那之后上游有更多的提交,所以现在我想变基,我想这就是我必须做的。
但我遇到了这些合并冲突:
First, rewinding head to replay your work on top of it...
Applying: Issue 135 homepage refresh
Using index info to reconstruct a base tree...
<stdin>:17: trailing whitespace.
%h4
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging app/views/layouts/application.html.haml
CONFLICT (content): Merge conflict in app/views/layouts/application.html.haml
Auto-merging app/views/home/index.html.haml
CONFLICT (content): Merge conflict in app/views/home/index.html.haml
Auto-merging app/views/home/_group_projects.html.haml
CONFLICT (content): Merge conflict in app/views/home/_group_projects.html.haml
Failed to merge in the changes.
Patch failed at 0001 Issue 135 homepage refresh
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".
I don't know how to fix these, please help.
我不知道如何解决这些问题,请帮忙。
回答by iltempo
Rebasing can be a real headache. You have to resolve the merge conflicts and continue rebasing. For example you can use the merge tool (which differs depending on your settings)
重新定位可能是一个真正令人头疼的问题。您必须解决合并冲突并继续变基。例如,您可以使用合并工具(根据您的设置而有所不同)
git mergetool
Then add your changes and go on
然后添加您的更改并继续
git rebase --continue
Good luck
祝你好运
回答by Uga Buga
When you have a conflict during rebase you have three options:
当您在变基期间遇到冲突时,您有三个选择:
You can run
git rebase --abort
to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called.You can run
git rebase --skip
to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included. It is very rare that you would choose this option.You can fix the conflict as iltempo said. When you're finished, you'll need to call
git rebase --continue
. My mergetool is kdiff3 but there are many more which you can use to solve conflicts. You only need to set your merge tool in git's settings so it can be invoked when you callgit mergetool
https://git-scm.com/docs/git-mergetool
您可以运行
git rebase --abort
以完全撤消变基。Git 会让你回到你的分支的状态,就像在调用 git rebase 之前一样。您可以运行
git rebase --skip
以完全跳过提交。这意味着有问题的提交引入的任何更改都不会包含在内。您很少会选择此选项。您可以像 iltempo 所说的那样解决冲突。完成后,您需要调用
git rebase --continue
。我的合并工具是 kdiff3,但还有更多可用于解决冲突的工具。你只需要在 git 的设置中设置你的合并工具,这样你就可以在调用https://git-scm.com/docs/git-mergetool时调用它git mergetool
If none of the above works for you, then go for a walk and try again :)
如果以上都不适合你,那就去散散步再试一次:)
回答by VonC
Note: with Git 2.14.x/2.15 (Q3 2017), the git rebase
message in case of conflicts will be clearer.
注意:使用 Git 2.14.x/2.15(2017 年第 3 季度),git rebase
发生冲突时的消息将更加清晰。
See commit 5fdacc1(16 Jul 2017) by William Duclot (williamdclt
).
(Merged by Junio C Hamano -- gitster
--in commit 076eeec, 11 Aug 2017)
参见William Duclot ( ) 的commit 5fdacc1(16 Jul 2017 )。(由Junio C Hamano合并-- --在076eeec 提交中,2017 年 8 月 11 日)williamdclt
gitster
rebase
: make resolve message clearer for inexperienced users
rebase
:让没有经验的用户更清楚地解决消息
Before:
前:
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort"
After:
后:
Resolve all conflicts manually,
mark them as resolved with git add/rm <conflicted_files>
then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".')
The git UI can be improved by addressing the error messages to those they help: inexperienced and casual git users.
To this intent, it is helpful to make sure the terms used in those messages can be understood by this segment of users, and that they guide them to resolve the problem.In particular, failure to apply a patch during a git rebase is a common problem that can be very destabilizing for the inexperienced user.
It is important to lead them toward the resolution of the conflict (which is a 3-steps process, thus complex) and reassure them that they can escape a situation they can't handle with "--abort
".
This commit answer those two points by detailing the resolution process and by avoiding cryptic git linguo.
git UI 可以通过将错误消息处理给他们帮助的人来改进:没有经验的和临时的 git 用户。
为此,确保这部分用户可以理解这些消息中使用的术语并指导他们解决问题是有帮助的。特别是,在 git rebase 期间未能应用补丁是一个常见问题,对于没有经验的用户来说可能会非常不稳定。
重要的是要引导他们解决冲突(这是一个 3 步过程,因此很复杂),并让他们放心,他们可以摆脱无法用“--abort
”处理的情况。
该提交通过详细说明解析过程和避免使用神秘的 git linguo 来回答这两点。
回答by baur
If you have a lot of commits to rebase, and some part of them are giving conflicts, that really hurts. But I can suggest a less-known approachhow to "squash all the conflicts".
如果您有很多要变基的提交,并且其中的某些部分会产生冲突,那真的很痛苦。但是我可以建议一种鲜为人知的方法来“消除所有冲突”。
First, checkout temp branch and start standard merge
首先,签出临时分支并开始标准合并
git checkout -b temp
git merge origin/master
You will have to resolve conflicts, but only once and only real ones. Then stage all files and finish merge.
你必须解决冲突,但只有一次,而且只有真正的冲突。然后暂存所有文件并完成合并。
git commit -m "Merge branch 'origin/master' into 'temp'"
Then return to your branch (let it be alpha) and start rebase, but with automatical resolving any conflicts.
然后返回您的分支(让它成为alpha)并开始变基,但会自动解决任何冲突。
git checkout alpha
git rebase origin/master -X theirs
Branch has been rebased, but project is probably in invalid state. That's OK, we have one final step. We just need to restore project state, so it will be exact as on branch 'temp'. Technically we just need to copy its tree(folder state) via low-level command git commit-tree. Plus merging into current branch just created commit.
分支已重新定位,但项目可能处于无效状态。没关系,我们还有最后一步。我们只需要恢复项目状态,因此它将与分支 'temp' 上的完全相同。从技术上讲,我们只需要通过低级命令git commit-tree复制它的树(文件夹状态)。加上合并到当前分支刚刚创建的提交。
git merge --ff $(git commit-tree temp^{tree} -m "Fix after rebase" -p HEAD)
And delete temporary branch
并删除临时分支
git branch -D temp
That's all. We did a rebase via hidden merge.
就这样。我们通过隐藏合并进行了变基。
Also I wrote a script, so that can be done in a dialog manner, you can find it here.
我还写了一个脚本,以便可以以对话方式完成,您可以在此处找到它。