git am失败后git status和git diff为空

Nic*_*ers 4 git merge-conflict-resolution

我在与通常不同的机器上进行开发,并且git的行为似乎与我记得的不同。

当我签出新的branch git checkout -b <new branch name>并尝试应用补丁时git am </path/to/file.patch>,补丁无法应用:

</path/to/file.patch>
Applying: <commit msg>
error: patch failed: <filename>:<line no>
error: <filename>: patch does not apply
Patch failed at <commit msg>
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Run Code Online (Sandbox Code Playgroud)

现在,当补丁无法应用时,我会在其他机器上发誓,git status并且git diff将用<<< HEAD >>>>标记显示修改后的文件,其中显示了我需要修复三种方式合并的位置。当前git status显示我正在执行某项am操作,但没有更改任何文件,就像一样git diff

我记错git了吗,或者我的另一台机器上是否安装了的旧版本,甚至设置了不同的配置选项?为什么git不显示合并冲突?我需要设置一个mergetool吗?我目前无法访问其他计算机,但我将在可能的情况下尝试用更多信息更新此帖子。

编辑:

git am --3way似乎就是我想要的。[0] [1]但似乎git am --3way <path/to/patch>git config --global am.threeWay true没有用。

啊,现在失败了,并显示了另一条消息:

</path/to/file.patch>
Applying: <commit msg>
fatal: sha1 information is lacking or useless (<filename>).            <-- new
error: could not build fake ancestor                                   <-- new
Patch failed at <commit msg>
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Run Code Online (Sandbox Code Playgroud)

类似,git am --3way </path/to/patch>失败:

error: patch failed: <file>:<lineno>
error: repository lacks the necessary blob to fall back on 3-way merge.
error: Makefile: patch does not apply
Run Code Online (Sandbox Code Playgroud)

也许这个补丁是无法弥补的?求助于patch -p1 < </path/to/path>应用第一个大块,而失败了第二个,所以我想我只需要手工完成即可。

我应该注意,我正在使用克隆的浅仓库--depth 1

[0] https://www.kernel.org/pub/software/scm/git/docs/git-am.html [1] https://www.kernel.org/pub/software/scm/git/docs/git-config.html

ruv*_*vim 10

关于以下错误:

fatal: sha1 information is lacking or useless (<filename>).
error: could not build fake ancestor
Run Code Online (Sandbox Code Playgroud)

git am -3尝试应用从另一个存储库生成的补丁时,也会发生此错误。解决方法是添加此存储库(例如 patch-origin)以供参考:

git remote add patch-origin <path>
git fetch patch-origin
Run Code Online (Sandbox Code Playgroud)

之后git应该就可以建祖了


Nic*_*ers 6

啊哈! 这样的帖子使我得到了答案。

两件事情出了问题:

将三种方式的合并设置为的默认行为git am

git config --global am.threeWay true

这是因为我做了一个浅表副本(即--depth 1)而感到困惑。我链接到的SO帖子解释说,没有足够的历史记录,警告fatal: sha1 information is lacking or useless是“没有足够的信息来构建三路合并”。

如果您进行了浅表复制以获取更多历史记录,则在本例中提到git会有所帮助...