How to apply a Perforce patch?

前提是你 提交于 2019-12-01 03:05:41

Perhaps Perforce's diff output format has changed, but @RumburaK's answer didn't work for me.

I had to modify it to convert the ==== header to diff's +++ and --- header format.

sed -Ee 's|==== (//.*)#[0-9]+(.*)|+++ \1\n--- \1|' < infile.txt > outfile.txt

infile.txt was generated with the following command (where 12335 was a shelved changelist): p4 describe -du -S 12345

outfile.txt was applied with the following command: patch -p3 -l < outfile.txt

Just found your question after saving some of my changes in a patch and reverting them in order to test some of the original code...

Assuming you're using a decent terminal emulator, this one time operation could take you up to an hour or so.

The good thing is that you can't run into this on a daily basis, as you probably will now use "-du" from now on, at least me I'm sure I will. Just copy and paste the file name as prompted:

$ patch -i cucu.diff 
can't find file to patch at input line 2
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|==== //depot/foo/boo.cpp#1 - /home/who/perforce/foo/boo.cpp ====
--------------------------
File to patch: 

<double-click!> to copy
<middle-click!> to paste

File to patch: /home/who/perforce/foo/boo.cpp <CR>

Perhaps you will have 100 files in the patch... keep clicking :-)

If you're looking for a subst expression (vim, sed):

s/.* - \(.*\) ====/+++: \1/

But - beware if you added sources (whole files, p4 add) their content probably won't be printed in the diff - in which case nobody will be able to re-patch them in...

Another answer:The p4 diff2 command supports a -u flag to generate diffs in GNU diff format.

From p4 help diff2:

The -u flag uses the GNU diff -u format and displays only files that differ. The file names and dates are in Perforce syntax, but the output can be used by the patch program.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!