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

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

From
SZSalikh Zakirov <salikh.zakirov@intel.com>
Date
May 26, 2006, 16:00 UTC
Message-ID
<4477262A.5000301@Intel.com>
Hello, 

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.

Is this a bug or known deficiency?

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 git commit -m "a modified" a git format-patch HEAD^ git reset --hard HEAD^ git am 0001*.txt ---------

The resulting output is --------- $ ./test defaulting to local storage area a: done. Committing initial tree 357c56061b96c1548b15168bc0d02e8d1a319e0b a: done. 0001-a-modified.txt

Applying 'a modified'

error: patch failed: a:1 error: a: patch does not apply Patch failed at 0001. When you have resolved this problem run "git-am --resolved". If you would prefer to skip this patch, instead run "git-am --skip". ---------

If I remove unix2dos calls and so the file has normal unix LF line endings, then the result is correct as expected

--------- $ ./test defaulting to local storage area Committing initial tree 6afc8719a182fed19980da0e53d13fba1f94dd3f 0001-a-modified.txt

Applying 'a modified'
Wrote tree 49f5181a399bbcaac1da3bf693c466a281c4a255
Committed: 2b0a2936d0a65b3511882b8e88586ab054dd15b2
---------
Next: Junio C Hamano
Message 1 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.