Subject: Re: [BUG?] Patches created with 'diff.noprefix=true' don't 'git apply'.

From: Jonathan Nieder <[email-masked]>
Date: Wed, 30 Apr 2014 19:40:42 -0700

Hi,

Nathan Collins wrote:

> Patches created with 'diff.noprefix=true' don't 'git apply' without
> specifying '-p0'.
>
> I'm not sure this is a bug -- the 'man git-apply' just says "Reads the
> supplied diff output (i.e. "a patch") and applies it to files" -- but
> I would expect patches I create locally to apply cleanly locally.

Sounds like a documentation bug, at least.  Any ideas for clearer
wording?

>                                                                   In
> real life the 'diff.noprefix=true' is in my ~/.gitconfig, so this was
> pretty confusing.

I personally think setting diff.noprefix is not very sane (it also
breaks "patch -p1"), and I suppose I should have been louder about
that when it was introduced.

Can you say more about the workflow you use that requires
diff.noprefix?  Maybe we can make other changes to improve it, too.

At first glance I don't suspect making diff.noprefix imply -p0 for
"git am" would be great, since that would generate the the opposite
problem when applying patches from the outside world.  But maybe we
need better autodetection and maybe noprefix is a good signal about
when to use it.

Another complication is that unlike 'git diff', 'git apply' is
plumbing that is meant to be useful and reliable for scripts.  And
unlike most plumbing, there is no higher-level command with similar
functionality for which we can experiment more freely with the UI.
Adding a new command to fix that might be a good direction toward
handling noprefix patches better.

[...]
> git show | git apply --reverse

The following which only uses plumbing commands should work:

	git diff-tree -p HEAD^! |
	git apply --reverse

Thanks for some food for thought,
Jonathan