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

Re: `ab | (cd cd && git apply -)' fails with v2.0.0

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 24, 2014, 17:19 UTC
Message-ID
<xmqqegxaad3r.fsf@gitster.dls.corp.google.com>
In-Reply-To
<53D116B9.3050809@drmicha.warpmail.net>
Michael J Gruber <git@drmicha.warpmail.net> writes:
Show 12 quoted lines
> Steffen Nurpmeso venit, vidit, dixit 24.07.2014 15:29:
>> Hello (again, psssssst, after a long time),
>> 
>> it happened yesterday that i needed to do
>> 
>>   $ git diff HEAD:FILE COMMIT:SAME-FILE |
>>   > (cd src && git apply -) 
>> ...
>
> Ah little more context would help. Are you diffing files in the subdir
> src, or a file at the root which happens to be present in the subdir src
> as well?

As the <treeish>:<path> form is not meant to produce "git apply" applicable patch in the first place, I am not sure what the OP is trying to achieve in the first place. Not just "how many leading levels to strip?" but "which file is being modified?" does not appear in a usable form. For example, here is what you would see:

    $ git diff HEAD:GIT-VERSION-GEN maint:GIT-VERSION-GEN
    diff --git a/HEAD:GIT-VERSION-GEN b/maint:GIT-VERSION-GEN
    index 40adbf7..0d1a86c 100755
    --- a/HEAD:GIT-VERSION-GEN
    +++ b/maint:GIT-VERSION-GEN
    @@ -1,7 +1,7 @@
    ...

and neither "HEAD:GIT-VERSION-GEN" nor "maint:GIT-VERSION-GEN" is the file being modified ("GIT-VERSION-GEN" is).

I would understand if the upstream of the pipe were
    $ git diff HEAD maint -- GIT-VERSION-GEN | ...
though.

Needless to say, if the place "cd" goes is not a worktree controlled by git, then "git apply" would not know where the top-level of the target tree is, so even though the input with the corrected command on the upstream side of the pipe tells it which file is being modified, it needs to be told with the proper -p<n> parameter how many leading levels to strip.

Previous: Michael J GruberNext: Michael J Gruber
Message 3 of 5 in “`ab | (cd cd && git apply -)' fails with v2.0.0”
  1. Steffen NurpmesoJul 24, 2014
  2. Michael J GruberJul 24, 2014
  3. Junio C HamanoJul 24, 2014
  4. Michael J GruberJul 25, 2014
  5. Steffen NurpmesoJul 25, 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.