强制 diff 到 git
当我尝试使用 git am 修补它时,进行 perforce diff 时,它显示“修补程序格式检测失败”。
如何从 perforce 获取更改并将其应用到 git 分支?
这是 diff 的前几行
==== //depot/a.c#162 - /asdf/a.c ====
4326a4327,4642
> /*
> *----------------------------------------------------------------------------
> *
> * --
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保使用
p4 diff -du
获取统一 diff 格式,与patch
,并且是(我相信)Git 理解的唯一格式。您可能还需要编辑补丁以删除 Perforce 语法;如您所见,文件名显示为
//depot/ac#162
,其中patch
和git apply
可能会解释为实际的文件名文件名;ac#162
。如果您的补丁中出现了#162
部分,请尝试删除它。并且根据您应用补丁的具体位置,您可能需要将
-p1
传递给patch
或git apply
以去除前导/
或-p2
删除整个主目录。Make sure you produce the diff with
p4 diff -du
to get the unified diff format, which works much better with tools likepatch
, and is (I believe) the only format that Git understands.You also may need to edit the patch to take out the Perforce syntax; as you can see, the file name appears as
//depot/a.c#162
, whichpatch
andgit apply
may be interpreting as the actual filename;a.c#162
. Try removing the#162
part if that appears in your patch.And depending exactly where you are applying the patch, you may need to pass
-p1
topatch
orgit apply
in order to strip off the leading/
, or-p2
to strip off the entire leading directory.使用
git apply
,或者失败使用patch(1)
,然后提交结果。Use
git apply
, or failing that usepatch(1)
directly, then commit the results.