git rebase合并冲突

pah*_*nin 64 git github git-rebase

我分叉了一个github仓库,并在我的github仓库上工作.
我已经提出拉动请求并且已经完成.

在那之后上游有更多的提交,所以现在我想要改变,我想这就是我必须要做的.
但我得到了这些合并冲突:

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".
Run Code Online (Sandbox Code Playgroud)

我不知道如何修复这些,请帮忙.

ilt*_*mpo 94

重新定位可能是一个真正的头痛.您必须解决合并冲突并继续重新定位.例如,您可以使用合并工具(根据您的设置而有所不同)

git mergetool
Run Code Online (Sandbox Code Playgroud)

然后添加并提交您的更改并继续

git rebase --continue
Run Code Online (Sandbox Code Playgroud)

祝好运

  • `git mergetool` 是做什么的? (6认同)
  • @iitempo您不需要进行提交。只需添加一个git就足以使重新设置继续进行。 (3认同)
  • 是变相是令人头疼,我可以使用git pull上游高手吗? (2认同)
  • 是的,你可以试试.不同之处在于,您的提交不会放在上游的提交之上.可能存在较少的合并冲突. (2认同)

Uga*_*uga 29

当您在rebase期间发生冲突时,您有三个选择:

  • 您可以运行git rebase --abort以完全撤消rebase.Git将返回到你的分支状态,就像调用git rebase之前一样.

  • 您可以运行git rebase --skip以完全跳过提交.这意味着将不包括由有问题的提交引入的任何更改.您很少选择此选项.

  • 你可以解决冲突,如iltempo所说.当你完成后,你需要打电话git rebase --continue.我的mergetool是kdiff3,但还有更多可用于解决冲突的东西.您只需要在git的设置中设置合并工具,以便在调用https://git-scm.com/docs/git-mergetool时调用它.git mergetool

如果以上都不适合你,那就去散步再试一次:)

  • 谢谢你散步,解决了我的问题. (37认同)

cha*_*haz 10

如果你不介意压缩成一个大的提交,那么我最简单的方法就是git reset --soft <rebase-target>从你当前的分支开始git commit

例如,你在你的分支上,你的变基目标是 origin/master。假设您没有未暂存/工作的更改:

# Merge and fix any conflicts from master
git merge origin/master
# Push your changes in case you mess up and want to start over from remote
git push
# Move HEAD to rebase target, leaving all your work staged
git reset --soft origin/master
# Commit staged changes as giant commit
git commit -m "feat(foo): new feature"
# Confirm your changes, run tests, etc. Then force push
git push -f
Run Code Online (Sandbox Code Playgroud)

您不必担心重做合并冲突,因为分支和变基目标之间的整个差异都已移至暂存区域,一切都准备好提交。


Von*_*onC 8

注意:使用Git 2.14.x/2.15(2017年第3季度),git rebase冲突情况下的消息将更加清晰.

请参阅William Duclot()提交5fdacc1(2017年7月16日).(由Junio C Hamano合并- -提交076eeec,2017年8月11日)williamdclt
gitster

rebase:让没有经验的用户更清楚地解决消息

之前:

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"
Run Code Online (Sandbox Code Playgroud)

后:

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".')
Run Code Online (Sandbox Code Playgroud)

可以通过将错误消息解决给他们帮助的人来改进git UI:缺乏经验和随意的git用户.
为了达到这个目的,确保这部分用户可以理解这些消息中使用的术语,并指导他们解决问题.

特别是,在git rebase期间未能应用补丁是一个常见问题,对于没有经验的用户而言可能非常不稳定.
重要的是引导他们解决冲突(这是一个三步骤的过程,因此很复杂)并向他们保证他们可以逃脱他们无法用" --abort" 处理的情况.
这个提交通过详细说明解决过程和避免含糊不清的git linguo来回答这两点.


bau*_*aur 5

如果您有很多要重新设置的提交,而其中有一部分正在产生冲突,那确实很痛苦。但是我可以建议一种鲜为人知的方法来“解决所有冲突”。

首先,签出临时分支并开始标准合并

git checkout -b temp
git merge origin/master
Run Code Online (Sandbox Code Playgroud)

您将必须解决冲突,但是只有一次,只有真正的冲突。然后暂存所有文件并完成合并。

git commit -m "Merge branch 'origin/master' into 'temp'"
Run Code Online (Sandbox Code Playgroud)

然后返回到您的分支(将其设置为alpha)并开始变基,但会自动解决所有冲突。

git checkout alpha
git rebase origin/master -X theirs
Run Code Online (Sandbox Code Playgroud)

分支已经重新设置了基础,但是项目可能处于无效状态。没关系,我们还有最后一步。我们只需要恢复项目状态,因此将与分支“ temp”上的状态完全相同。从技术上讲,我们只需要通过低级命令git commit-tree复制其(文件夹状态)。加上合并到当前创建的分支中的提交。

git merge --ff $(git commit-tree temp^{tree} -m "Fix after rebase" -p HEAD)
Run Code Online (Sandbox Code Playgroud)

并删除临时分支

git branch -D temp
Run Code Online (Sandbox Code Playgroud)

就这样。我们通过隐藏合并进行了重新设置。

我也写了一个脚本,所以可以通过对话的方式完成,您可以在这里找到它。

  • 这让我很头疼,谢谢!“项目可能处于无效状态”是什么意思?我做了所有事情,包括“git rebase origin/master -X theirs”,一切看起来都很好......我不愿意在不了解是否有必要的情况下进行最后的“合并”。 (3认同)
  • @jay 命令 `git rebase origin/master -X thoses` 只是一个机械合并冲突解决方案。有时它就足够了,不需要其他任何东西。但有时项目甚至无法编译。这就是为什么额外的提交有助于恢复正确的变基结果,这之前是通过传统合并完成的。我可以建议您进行最终合并,看看它是否会引入更改。 (2认同)
  • 我真正喜欢这个答案的是,1)我不必压制我所有仔细考虑的提交,2)可以毫不费力地穿过提交冲突的丛林。进行“常规”变基时,我会处理每个提交的冲突。如果您有 439 次提交,那么这可能是一个很大的过程。通过你的方法,我可以一次性处理所有冲突,然后重新建立基础。---&lt;--@ (2认同)