3

Taking perforce diff when I try to patch this using git am, it says "Patch format detection failed".

How do I get my changes from perforce and apply it to git branch?

This is the first few lines of diff

==== //depot/a.c#162 - /asdf/a.c ====
4326a4327,4642
> /*
>  *----------------------------------------------------------------------------
>  *
>  *  --
CharlesB
  • 86,532
  • 28
  • 194
  • 218

2 Answers2

7

Make sure you produce the diff with p4 diff -du to get the unified diff format, which works much better with tools like patch, 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, which patch and git 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 to patch or git apply in order to strip off the leading /, or -p2 to strip off the entire leading directory.

Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
  • Any idea how to get the diff generated using `describe` to be recognized by `patch`? – haridsv Apr 24 '12 at 07:02
  • Hi @Brian, is there any command to quickly delete all `#N`. Thanks! – Dien Nguyen Aug 27 '12 at 01:22
  • 1
    @dien don't have Perforce in front of me to check the exact format, but something like `sed -Ee 's|(//.*)#[0-9]+|\1|' output.patch` should do the trick. This is fairly imprecise, so check that it produced something sensible before trying to apply the patch. – Brian Campbell Aug 27 '12 at 13:14
0

Use git apply, or failing that use patch(1) directly, then commit the results.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • 1
    Why not, what errors do you get? What's your perforce diff tool and why didn't it generate proper patch formats? – Carl Norum Nov 27 '11 at 21:57
  • i did p4 diff > file and patch -p0 < /scratch/diffs/1st patch: **** Only garbage was found in the patch input. sreraku $ git apply /scratch/diffs/1st error: No changes – Sreeram Ravinoothala Nov 27 '11 at 21:59
  • Well given that example, you're not applying the same patch file you created. Is that a typo? Please edit your question and add the first 10 lines or so of `file`. – Carl Norum Nov 27 '11 at 22:02
  • Did you try `patch -p1`? It looks like you have extra file path information there you don't want to use. – Carl Norum Nov 27 '11 at 22:07
  • The diff output from perforce and git are incompatible by default. This will not work – Srikanth K. Apr 09 '13 at 02:09