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

Confusing documentation for git apply -p<n>

From
KEkelly elton <its.the.doc@gmail.com>
Date
Apr 27, 2018, 17:40 UTC
Message-ID
<CALVfKe_em046aO9QUqJ0TXcLh6Oe7ydYQKr9Zwvheq8RV4=43g@mail.gmail.com>
https://git-scm.com/docs/git-apply#git-apply--pltngt
>  -p<n>
> Remove <n> leading slashes from traditional diff paths. The default is 1.
This suggests to me the following outcomes:
1) home/user/repos/myrepo with -p1 becomes home/user/repos/myrepo
2) home/user/repos/myrepo with -p2 becomes home/user/repos/myrepo
3) /home/user/repos/myrepo with -p1 becomes home/user/repos/myrepo
4) /home/user/repos/myrepo with -p2 becomes home/user/repos/myrepo
5) //home/user/repos/myrepo with -p1 becomes /home/user/repos/myrepo
6) //home/user/repos/myrepo with -p2 becomes home/user/repos/myrepo
`Remove <n> leading slashes`...That's not really what's happening.
What seems to actually happen is that it is removing directories from the path:
1) home/user/repos/myrepo with -p1 becomes home/user/repos/myrepo
2) home/user/repos/myrepo with -p2 becomes user/repos/myrepo
This argument seems to be removing folders from the path, not slashes.

I'm sure it's doing both removing slashes and folders, but at different times, which makes it even more confusing to anyone trying to wrap their head around it.

-p1= /home/a -> home/a -p1= home/a -> home/a ?? Does this happen, or does it actually remove `home`??? -p2=/home/a -> home/a OR a ??? I have no idea after reading the docs and seeing different behavior. I literally have to experiment with it to know what it does in each scenario. -p2=home/a -> a ?? folder and slash removed.

All of this doesn't have to be so complicated, it's just being expressed in a complicated way.

Break this out into two separate functions maybe, or update the documentation so it's clearer how this behaves.

> -p<n> - number of folders in path to remove from the beginning of the path.
Not great, but clearer than what's there.

Thanks, Kelly Elton http://www.kellyelton.com

Next: Jeff King
Message 1 of 3 in “Confusing documentation for git apply -p<n>”
  1. kelly eltonApr 27, 2018
  2. apply: clarify "-p" documentationJeff King, May 10, 2018
  3. Junio C HamanoMay 11, 2018

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.