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

Re: [PATCH] Fix git-apply with -p greater than 1

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 22, 2010, 15:38 UTC
Message-ID
<20101022153803.GD9224@burratino>
In-Reply-To
<4CC194DF.9040803@lugmen.org.ar>
Fede wrote:
> Jonathan Nieder wrote:
Show 9 quoted lines
>> I had thought -p was only supposed to apply to traditional patches.
>> Maybe a documentation update would avoid confusion?
>>
>> 	-p<n>
>> 	   Remove <n> leading slashes from traditional diff paths.
>> 	   The default is 1.
>
> Currently, if the patch is mode-change only then the filename is taken
> from the line "diff --git ...".
Ah, found it:
commit 79ee194e52a140412da475e102145bad80d5d00a
Author: Shawn O. Pearce <spearce@spearce.org>
Date:   Wed Apr 4 11:19:14 2007 -0400
    Honor -p<n> when applying git diffs
    
    If the user is trying to apply a Git generated diff file and they
    have specified a -p<n> option, where <n> is not 1, the user probably
    has a good reason for doing this.  Such as they are me, trying to
    apply a patch generated in git.git for the git-gui subdirectory to
    the git-gui.git repository, where there is no git-gui subdirectory
    present.
    
    Users shouldn't supply -p2 unless they mean it.  But if they are
    supplying it, they probably have thought about how to make this
    patch apply to their working directory, and want to risk whatever
    results may come from that.
    
    Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
    Signed-off-by: Junio C Hamano <junkio@cox.net>
-- 8< --
Subject: Documentation: update description of "git apply -p"

The "git apply -p" (strip path components) option has gone through some changes since it was last documented:

 ec7fc0b (builtin-apply.c: pay attention to -p<n> when..., 2009-11-25)
 79ee194 (Honor -p<n> when applying git diffs, 2007-04-04)
 3e8a5db (git-apply: guess correct -p<n> value for non-git..., 2007-02-21)
 56185f4 (git-apply: require -p<n> when working in a subdirectory, 2007-02-19)
Document some of the new rules:
 - the -p option applies to both traditional and --git format diffs
 - in traditional diffs, since there is no customary standard -p value,
   'git apply' will try to guess
 - in all cases, the default is 1
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Thoughts?  Improvements?
diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
index 4a74b23..8bb7422 100644
--- a/Documentation/git-apply.txt
+++ b/Documentation/git-apply.txt
@@ -103,8 +103,11 @@ respectively, and the pathname will be enclosed in double quotes if
 any of those replacements occurred.
 
 -p<n>::
-	Remove <n> leading slashes from traditional diff paths. The
-	default is 1.
+	Remove <n> leading path components from paths found in the
+	diff. The default is 1 for --git format diffs.  For
+	traditional diffs, if this option is not supplied, 'git apply'
+	will try to detect an appropriate -p value, defaulting to 1
+	if there is not enough information to guess.
 
 -C<n>::
 	Ensure at least <n> lines of surrounding context match before
Previous: FedeNext: Junio C Hamano
Message 5 of 9 in “Fix git-apply with -p greater than 1”
  1. Fix git-apply with -p greater than 1Federico Cuello, Oct 21, 2010
  2. Junio C HamanoOct 22, 2010
  3. Jonathan NiederOct 22, 2010
  4. FedeOct 22, 2010
  5. Jonathan NiederOct 22, 2010
  6. Junio C HamanoOct 22, 2010
  7. Federico CuelloOct 22, 2010
  8. Fix git-apply with -p greater than 1Federico Cuello, Oct 25, 2010
  9. Junio C HamanoOct 22, 2010

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.