git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jonathan Nieder <jrnieder@gmail.com>
Date
May 1, 2014, 02:40 UTC
Message-ID
<20140501024042.GX9218@google.com>
In-Reply-To
<CAO8RVvdgN3U5hUEsJjYY9urfeVUDWwHiEur4NQp=H93W37RRnw@mail.gmail.com>
Hi,
Nathan Collins wrote:
Show 6 quoted lines
> 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

Previous: Nathan CollinsNext: Nathan Collins
Message 2 of 13 in “[BUG?] Patches created with 'diff.noprefix=true' don't 'git apply'.”
  1. Nathan CollinsMay 1, 2014
  2. Jonathan NiederMay 1, 2014
  3. Nathan CollinsMay 6, 2014
  4. Jonathan NiederMay 6, 2014
  5. Junio C HamanoMay 6, 2014
  6. Nathan CollinsMay 6, 2014
  7. Junio C HamanoMay 6, 2014
  8. Nathan CollinsMay 7, 2014
  9. Junio C HamanoMay 7, 2014
  10. Nathan CollinsMay 7, 2014
  11. Nathan CollinsMay 8, 2014
  12. Nathan CollinsMay 8, 2014
  13. Junio C HamanoMay 8, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.