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

Re: git-apply can't apply patches to CRLF-files

From
Junio C Hamano <junkio@cox.net>
Date
May 26, 2006, 18:05 UTC
Message-ID
<7virnsk6fe.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<4477262A.5000301@Intel.com>
Salikh Zakirov <Salikh.Zakirov@Intel.com> writes:
> git-apply can't apply the patch to file with windows-style CRLF line endings,
> even if the patch was generated by git-format-patch.
I do not think that is the case.
> Is this a bug or known deficiency?

This particular reproduction recipe looks like a PEBCAK; it does not reproduce for me, but I do not have/use unix2dos so I did DOSsy line endings a bit differently.

	git init-db
	echo 'abc@' | tr '[@]' '[\015]' >a
        git add a
        git commit -m initial
	echo 'def@' | tr '[@]' '[\015]' >>a
        git commit -a -m second
        git format-patch HEAD^
	git reset --hard HEAD^
        git am 0*.txt
Show 13 quoted lines
> The following script reproduces the problem
> ---------
> #!/bin/sh
> set -e
> mkdir trash
> cd trash
> git init-db
> echo "abc" > a
> unix2dos a
> git add a
> git commit -m "a added" a
> echo "cde" >> a
> unix2dos a

Here the first line of a ends with \r\n already end the second line ends with a \n. Does running unix2dos on that do a sensible thing on the first line? Compare it with my above recipe which appends DOSsy line at the end of the file.

Having said that, CRLF is unsafe for E-mail transfers anyway, so I think we would need a special option to tell git-apply that it should match '\n' that appears in the patch with '\r\n' in the file being patched. But I do not think that has anything to do with the breakage you saw in your reproduction recipe.

Previous: Salikh ZakirovNext: Salikh Zakirov
Message 2 of 5 in “git-apply can't apply patches to CRLF-files”
  1. Salikh ZakirovMay 26, 2006
  2. Junio C HamanoMay 26, 2006
  3. Fixed Cygwin CR-munging problem in mailsplitSalikh Zakirov, May 27, 2006
  4. Junio C HamanoMay 27, 2006
  5. Junio C HamanoMay 27, 2006

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.