删除/修改冲突后 Git rebase 将不会继续
我正在将我的 master 重新设置为 stage 分支,
git checkout stage
git rebase master
有时我删除了两个文件,然后根据 GIT 修改了这两个文件。
warning: too many files, skipping inexact rename detection
CONFLICT (delete/modify): test-recommendation-result.php deleted in HEAD and modified in [Bug] Fix test recommender. Version [Bug] Fix test recommender of test-recommendation-result.php left in tree.
CONFLICT (delete/modify): test-recommendation.php deleted in HEAD and modified in [Bug] Fix test recommender. Version [Bug] Fix test recommender of test-recommendation.php left in tree.
Failed to merge in the changes.
Patch failed at 0015.
我想说“是的,git,继续删除这些文件”所以....
git rm test-recommendation-result.php
git rm test-recommendation.php
git rebase --continue
Git 说:
Applying [Bug] Fix test recommender
No changes - did you forget to use 'git add', Stupid?
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
我说“不要叫我“愚蠢”,只做我告诉你做的事!”
我们现在陷入僵局。谁是对的?我该如何解决这个问题?
I'm in the middle of a rebase of my master to a stage branch
git checkout stage
git rebase master
At some time I deleted two files then modified the two files according to GIT.
warning: too many files, skipping inexact rename detection
CONFLICT (delete/modify): test-recommendation-result.php deleted in HEAD and modified in [Bug] Fix test recommender. Version [Bug] Fix test recommender of test-recommendation-result.php left in tree.
CONFLICT (delete/modify): test-recommendation.php deleted in HEAD and modified in [Bug] Fix test recommender. Version [Bug] Fix test recommender of test-recommendation.php left in tree.
Failed to merge in the changes.
Patch failed at 0015.
I want to say "Yeah git, go ahead and delete those files" so ....
git rm test-recommendation-result.php
git rm test-recommendation.php
git rebase --continue
Git says:
Applying [Bug] Fix test recommender
No changes - did you forget to use 'git add', Stupid?
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
I say "Don't call me "Stupid" and just do what I told you to do!"
We are now at a standoff. Who is right and how do I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
执行
git add -A
,然后执行git rebase --continue
。这应该添加所有更改 - 包括删除文件,然后继续。无法保证提交没有其他不冲突且应合并的文件。 git rebase --skip 会丢失这些文件。你不想要这样。
do
git add -A
followed bygit rebase --continue
. This should add all changes - including your removal of the files and then continue.There is no guarantee that the commit didn't have other files that did not conflict and should be merged.
git rebase --skip
would lose those files. You don't want that.当所有其他方法都失败时,请阅读该消息。
此补丁试图修改两个文件,但它们已被删除;再次删除它们没有任何作用。
只需运行 git rebase --skip 即可。
When all else fails, read the message.
This patch is trying to modify two files, but they have already been deleted; deleting them again did nothing.
Just run
git rebase --skip
.当提交添加了与现有文件冲突的二进制文件时,我遇到了这个问题。
我的方法是:
吉特又高兴了。 :)
I hit this when a commit added a binary file that conflicted with an existing file.
I got by it by:
Git was happy again. :)
正如我的问题:
当我执行 git add . 时,我的所有更改都消失了。我需要更改任何文档(只是添加一些更改,例如添加注释)并执行 git add . 比 git rebase --continue 为我工作。这是 git 的一个已知错误
as my problem:
when I did
git add .
all of my changes disappeared. I needed to change any document (just to add little change, for example adding comment) and dogit add .
thangit rebase --continue
worked for me. It is a know bug with git没有一个神奇的命令序列可以始终运行来解决这种情况。如果有的话,GIT 的开发人员将只执行该操作,而不会打扰用户。
请考虑,如果您选择/移植/向后移植影响重构或重命名的文件的更改,也可能会发生此错误。
例如,假设您有一个名为
support/1.0
的分支,如下所示:现在,假设在版本 1.0 和 1.5 之间,该分支进行了重构。所以现在
release/1.5
看起来像这样:现在,假设您有一个来自 1.5 版本的功能分支,您正尝试将其反向移植到基于
support/ 的功能分支1.0
。在此提交中,对 1.5 版中的所有三个文件(MyClass.java
、ANewClass.java
和MyOtherClass.java
)进行了更改。如果您尝试使用 rebase 或普通的cherry pick 来帮助向后移植,则可能会发生以下两种情况之一:
如果文件在移植更改过程中被重命名,
或者在更改的直接父级提交中
移植后,GIT内置的重命名检测可能会发现这些
文件是具有原始名称的文件的后代,并且简单地
将更改应用到原始文件。
如果文件在历史上足够远的时候被重命名
版本 1.5(版本 1.0 发布后),GIT 会告诉您
文件在
release/1.0
中被删除,因为它没有知道 1.0 中的哪些文件对应于 1.5 中的更改。
ANewClass.java
几乎肯定会触发有关已删除的错误,除非它被添加到正在向后移植的更改之一中。因此,如果您盲目地遵循一组命令来解决这种情况,代码可能会丢失,因此 GIT 会提示您进行手动指导。
There is not one magic sequence of commands to always run to solve this situation. If there were, GIT's developers would just perform that action and not bother the user.
Consider that this error can also happen if you're cherry picking / transplanting / backporting changes that affect a file that was re-factored or renamed.
For example, say that you have branch called
support/1.0
that looks like this:Now, suppose that between versions 1.0 and 1.5, this got refactored. So now
release/1.5
looks like this:Now, let's say that you have a feature branch from release 1.5 that you're trying to back-port to a feature branch based off of
support/1.0
. In that commit, there were changes to all three files from release 1.5 (MyClass.java
,ANewClass.java
, andMyOtherClass.java
).If you try to use rebase or plain cherry pick to help with the back-port, one of two things may happen:
If the files got renamed as part of the changes being transplanted,
or among the immediate parent commits of the changes being
transplanted, GIT's built-in rename detection may catch that these
files are descendants of the files with original names, and simply
apply the changes to the original files.
If the files got renamed sufficiently far back in the history of
release 1.5 (after release 1.0 shipped), GIT will tell you that the
files were deleted in
release/1.0
because it doesn'tknow what files in 1.0 correspond to the changes from 1.5.
ANewClass.java
will almost certainly trigger the error about having been deleted, unless it was added in one of the changes being back-ported.Hence, because code might get lost if you blindly follow one set of commands to resolve this situation, that's why GIT prompts you for manual guidance.
如果您做了像我这样的事情,因为该文件应该被忽略,但在某些时候却没有被忽略 - 所以它最终进入源代码管理,从文件系统中删除文件,然后中止变基。
之后您可以重新启动并且不会出现此错误。
这不是一个理想的解决方案,但不幸的是,一旦这种情况发生,我没有找到任何其他可接受的补救措施。
If you've done something like me where it's because the file should have been ignored and at some point it wasn't - so it ended up in source control, delete the files from the filesystem and then abort the rebase.
After that you can restart and not get this error.
It's not an ideal solution, but unfortunately I didn't find any other acceptable remedy for this situation once it occurred.