如果 git-am 失败并显示“索引中不存在”怎么办?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19115772/
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
What to do if git-am fails with “does not exist in index”?
提问by a1an
I have a patch that gives out the following output when I try to apply it with git am
当我尝试使用 git am 应用它时,我有一个补丁会给出以下输出
Checking patch old/filename...
error: old/filename: does not exist in index
Within the patch old/filename is actually moved to new/filename but it seems the original file is already missing from the source tree.
在补丁中 old/filename 实际上被移动到 new/filename 但似乎原始文件已经从源树中丢失了。
So what is the error about and how to solve / work-around it? Can it just be ignored (with --reject or so)?
那么错误是什么以及如何解决/解决它?可以忽略它吗(使用 --reject 左右)?
采纳答案by Jacques
The patch was not created against the correct source tree.
补丁不是针对正确的源代码树创建的。
One way this could happen:
这可能发生的一种方式:
Assume your original branch (the one you want to apply the patch to) has commits:
假设你的原始分支(你想应用补丁的那个)有提交:
- 1a -> 1b -> 1c -> 1d
- 1a -> 1b -> 1c -> 1d
This branch is then cloned, and new commits are made:
然后克隆这个分支,并进行新的提交:
- 1a -> 1b -> 1c -> 1d -> 1e
- 1a -> 1b -> 1c -> 1d -> 1e
Commit 1e included old/filename
提交 1e 包括旧的/文件名
Now you do the work in the patch, based on the second branch, not the original one:
现在您在补丁中完成工作,基于第二个分支,而不是原始分支:
- 1a -> 1b -> 1c -> 1d -> 1e -> 1f
- 1a -> 1b -> 1c -> 1d -> 1e -> 1f
Commit 1f included the rename old/filename -> new/filename
提交 1f 包括重命名旧/文件名 -> 新/文件名
Now, if you create a patch for commit 1f, you won't be able to apply it on top of commit 1d, because commit 1e is missing where old/filename was added to the index/repository.
现在,如果您为 commit 1f 创建补丁,您将无法在 commit 1d 之上应用它,因为在将 old/filename 添加到索引/存储库的地方缺少 commit 1e。
回答by Felipe
You can use --rejectto get it to do its
best and output the rest in .rejfiles. Then you can fix it up
manually and commit.
您可以使用--reject让它发挥最大作用并将其余部分输出到.rej文件中。然后你可以手动修复它并提交。
Tip extracted from: Raymes Khoury.
提示摘自:Raymes Khoury。

