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

Re: Bug Report for git apply

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Apr 11, 2019, 20:17 UTC
Message-ID
<20190411201718.GJ8796@szeder.dev>
In-Reply-To
<408662419.10955610.1555010182939.JavaMail.zimbra@zimbra.ccs.neu.edu>
On Thu, Apr 11, 2019 at 03:16:22PM -0400, Can Gemicioglu wrote:
> I noticed a problem when trying to apply a patch file that contained
> many separate patches in a single file.

To quote the first line of its manpage :) 'git apply' is meant to "Apply a patch to files and/or to the index". Note the singular "a patch"; not multiple patches in the same or multiple files.

Use 'git am' instead, that is its job, and as you noted, it works.
Show 20 quoted lines
> Trying to apply this patch gave me a "No such file or directory" error for one of the files in the middle and after looking around I realised this file was also created earlier in the patch. I tested this myself with these steps and saw a similar error:
> 
> 1. Create a new file and commit.
> 2. Move the file to a different folder and commit.
> 3. Create a single patch for these 2 commits by using git format-patch and concatenating the two resulting files (01.patch, 02.patch) into one (combined.patch).
> 4. Roll back to 2 commits earlier.
> 
> At that point if I try to use 'git apply combined.patch', it will
> throw the same no such file error. However, if I use 'git am
> combined.patch' instead it works. If I apply the first 2 patches
> separately instead, using 'git apply 0*' it also works but if I
> first try to check if it will work with 'git apply --check 0*' it
> actually throws the same error again.
> 
> I'm guessing there's something like a check to make sure the file exists that throws an error even if the file was going to be created by previous commits.
> 
> Tested on git version 2.21.0 on Ubuntu 18.04
> 
> Best,
> Can Gemicioglu
Previous: Can Gemicioglu
Message 2 of 2 in “Bug Report for git apply”
  1. Can GemiciogluApr 11, 2019
  2. SZEDER GáborApr 11, 2019

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.