git status和git diff在失败的git am之后为空 [英] git status and git diff empty after failed git am

查看:846
本文介绍了git status和git diff在失败的git am之后为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我检出一个新的分支时 git checkout -b <新分支名称> ,并尝试应用一个补丁 git am< /path/to/file.patch> ,该补丁未能适用:

 < /path/to/file.patch> 
应用:< commit msg>
错误:补丁失败:<文件名>:< line no>
错误:<文件名> ;:修补程序不适用
修补程序在< commit msg>失败。
失败补丁的副本见于:.git / rebase-apply / patch
当你解决了这个问题时,运行git am --continue。
如果您不想跳过此修补程序,请运行git am --skip。
要恢复原始分支并停止修补,请运行git am --abort。

现在我在其他机器上宣布补丁无法应用时, git状态 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> 
应用:< commit msg>
致命:sha1信息缺乏或无用(< filename>)。 < - 新
错误:无法建立假祖先< - 新
<提交信息>修补程序失败
失败补丁的副本见于:.git / rebase-apply / patch
当你解决了这个问题时,运行git am --continue。
如果您不想跳过此修补程序,请运行git am --skip。
要恢复原始分支并停止修补,请运行git am --abort。

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

 错误:补丁失败:< file>:< lineno> 
错误:存储库缺少必要的blob以回退3路合并。
错误:Makefile:补丁不适用

也许这个补丁是不可挽回的?诉诸 patch -p1 < < / path / to / path> 会应用第一个人,并且第二个人会失败,所以我想我只需要手动完成。



我应该注意到,我正在使用 - 深度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

解决方案

这个帖子让我得到了答案。



两件事出错:



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



git config --global am.threeWay true



事实上,我做了一个浅拷贝(即 - 深度1 )。我链接的SO帖子解释说,没有足够的历史记录,警告致命:sha1信息缺失或无用说没有足够的信息来构建三路合并。



如果你已经做了一个浅拷贝来获取更多的历史记录,这将有助于它在这种情况下提及git。


I'm developing on a different machine than I usually do, and it seems that git is behaving differently than I remember.

When I checkout a new branch git checkout -b <new branch name>, and try to apply a patch git am </path/to/file.patch>, the patch fails to apply:

</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".

Now I swear on my other machines when a patch fails to apply, git status and git diff will show the file as modified with <<< HEAD >>>> markers showing where I need to fix the three way merge. Currently git status shows I'm in the middle of an am operation, but no files changed, as does git diff.

Am I mis-remembering or does my other machine maybe have an older version of git, or even a different config option set? Why does git not show a merge conflict? Do I need to set a mergetool? I don't have access to my other machine at the moment, but I'll try to update this post with more info when I can.

edit:

git am --3way seems to be what I want. [0][1] But neither git am --3way <path/to/patch> nor git config --global am.threeWay true seem to work.

ah, it's failing with a different message now:

</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".

Similary, git am --3way </path/to/patch> fails with:

error: patch failed: <file>:<lineno>
error: repository lacks the necessary blob to fall back on 3-way merge.
error: Makefile: patch does not apply

Maybe this patch is irredeemable? Resorting to patch -p1 < </path/to/path> applies the first hunk and fails for the second, so I guess I'll just have to do this by hand.

I should note that I'm working out of a shallow repo cloned with --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

解决方案

Aha! This SO post led me to an answer.

Two things going wrong:

set three way merge as the default behavior of git am:

git config --global am.threeWay true

this was confounded by the fact that I had done a shallow copy (ie. --depth 1). The SO post I linked to explains that without enough history, the warning fatal: sha1 information is lacking or useless is saying "not enough info to construct a three way merge."

It would be helpful it git mentioned in this case if you had done a shallow copy to fetch more history...

这篇关于git status和git diff在失败的git am之后为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆