{"thread":{"id":"26887","subject":"git-am cannot apply git format-patch -M","startedAt":"2011-03-28T07:44:34Z","lastAt":"2011-03-28T12:14:12Z","messageCount":2,"participants":["Maarten Billemont","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"164412","messageId":"09D72CB4-1B48-4799-B0D5-DB54942D840F@gmail.com","threadId":"26887","inReplyTo":null,"subject":"git-am cannot apply git format-patch -M","fromName":"Maarten Billemont","fromEmail":"lhunath@gmail.com","sentAt":"2011-03-28T07:44:34Z","receivedAt":"2011-03-28T07:44:34Z","isPatch":false,"sender":{"key":"lhunath@gmail.com","avatar":"https://gravatar.com/avatar/bc5b6a8b0cdd6a29c7019afb479286896c37dd293484d641de4bdb186f8a9f80?d=mp&s=160"},"body":"I've created a series of patches for my local commits using:\n\ngit format-patch -M -C ...\n\nThe resulting patch files contain hunks like:\n\ndiff --git a/file1 b/file2\nsimilarity index 93% \nrename from file1\nrename to file2\nindex 7cf3a09..88c9c13 100644\n--- a/file1\n+++ b/file2\n[...]\n\ngit-am fails at applying these hunks, failing with:\n\nApplying: [commit description]\nfatal: git apply: bad git-diff - inconsistent old filename on line 109\nPatch failed at [HEAD commit]\nWhen you have resolved this problem run \"git am --resolved\".\nIf you would prefer to skip this patch, instead run \"git am --skip\".\nTo restore the original branch and stop patching run \"git am --abort\".\n\nAdditionally, I'd like to report that the line number reported by git-am in this error message does not reflect the actual line number of the problem in the patch file.  The reported line number is offset by -[amount of lines before the [---] line in the patch file], which makes understanding the error message hard, confusing and potentially misleading."},{"id":"164425","messageId":"20110328121412.GB9232@sigill.intra.peff.net","threadId":"26887","inReplyTo":"09D72CB4-1B48-4799-B0D5-DB54942D840F@gmail.com","subject":"Re: git-am cannot apply git format-patch -M","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-03-28T12:14:12Z","receivedAt":"2011-03-28T12:14:12Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Mar 28, 2011 at 09:44:34AM +0200, Maarten Billemont wrote:\n\n> I've created a series of patches for my local commits using:\n> \n> git format-patch -M -C ...\n> \n> The resulting patch files contain hunks like:\n> \n> diff --git a/file1 b/file2\n> similarity index 93% \n> rename from file1\n> rename to file2\n> index 7cf3a09..88c9c13 100644\n> --- a/file1\n> +++ b/file2\n> [...]\n> \n> git-am fails at applying these hunks, failing with:\n> \n> Applying: [commit description]\n> fatal: git apply: bad git-diff - inconsistent old filename on line 109\n> Patch failed at [HEAD commit]\n\nI can't replicate your problem using this script:\n\n  git init repo && cd repo\n\n  perl -le 'print for(1 .. 100)' >file1\n  git add file1\n  git commit -m 'add file1'\n\n  sed 50d file1 >file2\n  rm file1\n  git add -A\n  git commit -m 'move file1 to file2, with tweak'\n\n  git format-patch -M --stdout -1 >patch\n  git checkout -b other HEAD^\n  git am patch\n\nwhich generates a patch like the one you mention above. Does that script\nwork for you? If not, what git version are you using? If it does work,\nthen perhaps there is something more complex going on in your real repo.\nCan you show us a more complete example, with the real filenames?\n\n> Additionally, I'd like to report that the line number reported by\n> git-am in this error message does not reflect the actual line number\n> of the problem in the patch file.  The reported line number is offset\n> by -[amount of lines before the [---] line in the patch file], which\n> makes understanding the error message hard, confusing and potentially\n> misleading.\n\nYes. \"git am\" splits the email into pieces and just feeds the patch\nportion to \"git apply\". The lines it is referencing are in\n.git/rebase-apply/patch. It would perhaps be useful if \"git apply\" gave\nthe filename in addition to the line number (alternatively, \"git am\"\ncould mention the filename after a failed apply).\n\n-Peff\n"}]}