即使所有合并冲突都已解决,Git rebase --continue 也会抱怨

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8523776/
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-10 12:31:04  来源:igfitidea点击:

Git rebase --continue complains even when all merge conflicts have been resolved

gitrebase

提问by Lucas

I am facing an issue that I am not sure how to resolve.

我正面临一个我不知道如何解决的问题。

I did a rebase against master from my branch:

我从我的分支对 master 进行了 rebase:

git rebase master

and got the following error

并得到以下错误

 First, rewinding head to replay your work on top of it...
 Applying: checkstyled.
 Using index info to reconstruct a base tree...
 Falling back to patching base and 3-way merge...
 Auto-merging AssetsLoader.java
 CONFLICT (content): Merge conflict in AssetsLoader.java
 Failed to merge in the changes.
 Patch failed at 0001 checkstyled.

So I went to my favourite editor, fixed the 1 line conflict, saved the file and did a git status and got the following output:

所以我去了我最喜欢的编辑器,修复了 1 行冲突,保存文件并执行 git status 并得到以下输出:

 # Not currently on any branch.
 # Changes to be committed:
 #   (use "git reset HEAD <file>..." to unstage)
 #
 #  modified:   PassengerContactHandler.java
 #
 # Unmerged paths:
 #   (use "git reset HEAD <file>..." to unstage)
 #   (use "git add/rm <file>..." as appropriate to mark resolution)
 #
 #  both modified:      AssetsLoader.java
 #

I did a git add AssetsLoader.java and a git status and got the following:

我做了一个 git add AssetsLoader.java 和一个 git status 并得到以下结果:

 # Not currently on any branch.
 # Changes to be committed:
 #   (use "git reset HEAD <file>..." to unstage)
 #
 #  modified:   AssetsLoader.java
 #  modified:   PassengerContactHandler.java
 #

and when I did git rebase --continue I get:

当我执行 git rebase --continue 时,我得到:

git rebase --continue
You must edit all merge conflicts and then
mark them as resolved using git add

I know I can skip the patch and continue the rebase, but I am not sure if the changes in PassengerContactHandler.java will be rebased into my branch or not.

我知道我可以跳过补丁并继续重新设置基准,但我不确定PassengerContactHandler.java 中的更改是否会重新设置到我的分支中。

so I am not sure, How should I proceed?

所以我不确定,我应该如何进行?

Edit: Could it be that the file with the resolved conflict is exactly like the original version?

编辑:会不会是冲突已解决的文件与原始版本完全一样?

Thanks a lot, Lucas

非常感谢,卢卡斯

Edit, it just happened to me again:

编辑,它又发生在我身上:

It just happened to me again,

刚刚又发生在我身上

(307ac0d...)|REBASE)$ git status
# Not currently on any branch.
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   assets/world/level1/Level-1.xml
#   modified:   George.java
#   modified:   DefaultPassenger.java
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   mb-art/originalAssets/27dec/

((307ac0d...)|REBASE)$ git rebase --continue

((307ac0d...)|REBASE)$ git rebase --continue

You must edit all merge conflicts and then
mark them as resolved using git add

git --version

git --version

git version 1.7.1

回答by jonasfh

This happens because when fixing a conflict, you removed all code in the patch beeing applied to the branch you are rebasing on. Use git rebase --skipto continue.

发生这种情况是因为在修复冲突时,您删除了应用于您所基于的分支的补丁中的所有代码。使用git rebase --skip继续。

A bit more details:

更多细节:

Normally, when fixing a conflict during rebasing, you will edit the conflicting file, keeping some or all of the code in the patch currently being applied to the branch you rebase on. After fixing the patch and doing

通常,在 rebase 期间修复冲突时,您将编辑冲突文件,保留当前应用于您 rebase 的分支的补丁中的部分或全部代码。修复补丁后做

git add your/conflicted/file
git status

you will get a (usually green) line showing the modified file

你会得到一条(通常是绿色)行显示修改后的文件

modified: your/conflicted/file

修改:您的/冲突/文件

git rebase --continue will work fine in this situation.

git rebase --continue 在这种情况下可以正常工作。

Sometimes, however, when resolving the conflict, you remove everything in your new patch, keeping only code from the branch you rebased on. Now when you add the file, it will be exactly like the one you tried to rebase on. git status will show no green line displaying the modified files. Now, if you do

然而,有时在解决冲突时,您会删除新补丁中的所有内容,只保留您重新基于的分支中的代码。现在,当您添加文件时,它将与您尝试重新创建的文件完全一样。git status 不会显示显示修改后的文件的绿线。现在,如果你这样做

git rebase --continue

git will complain with

git会抱怨

No changes - did you forget to use 'git add'?

没有变化 - 您是否忘记使用“git add”?

What git actually wants you to do in this situation is to use

在这种情况下,git 实际上希望你做的是使用

git rebase --skip

to skip the patch. Previously I never did this, as I was always unsure what would actually be skipped if I did, it was not obvious to me what "skip this patch" really meant. But if you get no green line with

跳过补丁。以前我从来没有这样做过,因为我总是不确定如果我这样做实际上会跳过什么,我不清楚“跳过这个补丁”的真正含义。但是如果你没有得到绿线

modified: your/conflicted/file

修改:您的/冲突/文件

after editing the conflicted file, adding it, and doing git status, then you can be pretty sure you removed the whole patch, and you can instead use

在编辑冲突文件、添加它并执行 git status 之后,您可以非常确定您删除了整个补丁,并且可以改为使用

git rebase --skip

to continue.

接着说。

The original post said this sometimes works:

git add -A
git rebase --continue
# works magically?

原来的帖子说这有时有效:

git add -A
git rebase --continue
# works magically?

... but don't rely on this (and be sure not to add leftover files in your repository folders)

...但不要依赖于此(并确保不要在存储库文件夹中添加剩余文件)

回答by acme

Seems to be a bug in Git 1.7

似乎是 Git 1.7 中的一个错误

Here's a good article on how to solve this.

这是一篇关于如何解决这个问题的好文章

Basically it should work, if you do a

基本上它应该工作,如果你做

git diff

after resolving your conflicts and then

解决您的冲突后,然后

git rebase --continue

should work.

应该管用。

回答by ScottyBlades

I got this warning when I had unstaged files. Make sure you don't have any unstaged files. If you don't want the unstaged files changes, then discard the changes with git rm <filename>.

当我有未暂存的文件时,我收到了这个警告。确保您没有任何未暂存的文件。如果您不想更改未暂存的文件,请使用git rm <filename>.

回答by primulaveris

After fixing the conflict, make sure the changed files(s) are added to your staged files. This solved the problem for me.

解决冲突后,确保将更改的文件添加到暂存文件中。这为我解决了这个问题。

回答by Batkins

Try running this in your command line:

尝试在命令行中运行它:

$ git mergetool

Should bring up an interactive editor allowing you to resolve the conflicts. Easier than trying to do it manually, and also git will recognize when you do the merge. Will also avoid situations where you don't fully merge by accident that can happen when you try to do it manually.

应该打开一个交互式编辑器,允许您解决冲突。比手动尝试更容易,而且 git 会识别您何时进行合并。还将避免您尝试手动执行时可能发生的意外未完全合并的情况。

回答by carpii

Ive just had this problem, and whilst I think there might be a few causes, here's mine...

我刚刚遇到了这个问题,虽然我认为可能有几个原因,但这是我的......

I had a git pre-commit hook which rejected commits under certain conditions. This is fine when committing manually, since it will display the output of the hook, and I can either fix it or choose to ignore it using commit --no-verify.

我有一个 git pre-commit 钩子,它在某些条件下拒绝提交。这在手动提交时很好,因为它会显示钩子的输出,我可以修复它或使用 commit --no-verify 选择忽略它。

The problem seems to be that when rebasing, rebase --continue will also call the hook (in order to commit the lastest bout of changes). But rebase will not display the hook output, it'll just see that it failed, and then spit out a less specific error saying 'You must edit all merge conflicts and then mark them as resolved using git add'

问题似乎是在变基时,变基 --continue 也会调用钩子(为了提交最新的更改)。但是 rebase 不会显示钩子输出,它只会看到它失败,然后吐出一个不太具体的错误,说“您必须编辑所有合并冲突,然后使用 git add 将它们标记为已解决”

To fix it, stage all your changes, and instead of doing 'git rebase --continue', try a 'git commit'. If you are suffering from the same hook problem, you should then see the reasons why its failing.

要修复它,请暂存所有更改,而不是执行 'git rebase --continue',而是尝试执行 'git commit'。如果您遇到同样的钩子问题,那么您应该看看它失败的原因。

Interestingly, whilst git rebase doesn't display the output from git hook, it does accept a --no-verify to bypass the hooks.

有趣的是,虽然 git rebase 不显示来自 git hook 的输出,但它确实接受 --no-verify 来绕过钩子。

回答by Ether

You missed a merge conflict in AssetsLoader.java. Open it up and look for conflict markers (">>>>", "====", "<<<<<") and then do git add again. Do a 'git diff --staged' if you're having difficulty finding it.

您错过了 AssetsLoader.java 中的合并冲突。打开它并查找冲突标记(“>>>>”、“====”、“<<<<<”),然后再次执行 git add。如果您很难找到它,请执行 'git diff --staged'。

回答by Ghislain

I just stumbled on the issue. I would not git rebase --skipbecause git statusclearly show modifications stagged, which I wanted to keep. Though I had some extra files that came unexpectedly. I resolved with

我只是偶然发现了这个问题。我不会git rebase --skip因为git status清楚地显示修改交错,我想保留。虽然我有一些意外的额外文件。我解决了

git checkout .

to remove unstagged modifications, then git rebase --continuesucceeded.

删除未标记的修改,然后git rebase --continue成功。

回答by gsalgadotoledo

Once you fixed your changes you might forget to run 'git add -A'

修复更改后,您可能会忘记运行 'git add -A'

git add -A
git rebase --continue