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

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

From
Nathan Collins <nathan.collins@gmail.com>
Date
May 1, 2014, 01:36 UTC
Message-ID
<CAO8RVvdgN3U5hUEsJjYY9urfeVUDWwHiEur4NQp=H93W37RRnw@mail.gmail.com>

Bug? ====

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. In real life the 'diff.noprefix=true' is in my ~/.gitconfig, so this was pretty confusing.

Here's an old bug that's kind of related: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=607044

I'm using Git 1.9.2.

Example =======

Create a repo with a test commit:
  git init bug.git
  cd bug.git
  git add test
  git commit test -m Test

Revert the test commit in a contrived way (like 'git revert HEAD --no-commit; git reset'). This works:

  git -c diff.noprefix=false show | git -c diff.noprefix=false apply --reverse
And this works:
  git reset --hard
  git -c diff.noprefix=true show | git -c diff.noprefix=true apply -p0 --reverse
But this fails:
  git reset --hard
  git -c diff.noprefix=true show | git -c diff.noprefix=true apply --reverse
    fatal: git diff header lacks filename information when removing 1
leading pathname component (line 12)

Use Case ========

Partially reverting a commit:
http://git.661346.n2.nabble.com/Revert-a-single-commit-in-a-single-file-td6064050.html#a6064406
Cheers,
-nathan
Next: Jonathan Nieder
Message 1 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.