Search code examples
gitnewlinepatchcarriage-returnlinefeed

Git CRLF and LF line ending on windows/linux


I am working on a project which uses both CRLF and LF line endings. I am working on windows.

  • I created a patch that converts a file from using CRLF line endings to LF line endings.
  • I then formatted the patch with git format-patch. When I open this patch, it has correct LF line endings. The patch says the file is similar at 97% (only the line endings have been changed).
  • I sent it to someone using git send-email. When I observe the mail sent with wireshark, all the line endings have been converted to CRLF.
  • When someone else receive this patch (working on windows aswell), all the line endings are CRLF in the patch.
  • The patch can be applied, but the file which should have seen its line endings modified remains the same: no LF line ending conversion. When using git show HEAD, the file is said to be similar at 100%, even though the patch being applied said there should be a similarity of 97%.

How is it possible to send a patch with LD line ending on windows ? Thanks


Solution

  • Don't forget to add a .gitattributes rule for that file, in order to force lf for that file

    a_file text=auto eol=lf
    

    But regarding your send-email issue, see "git am/format-patch: control format of line endings", try and use git send-email --transfer-encoding=base64, to make sure everything is preserved (including eol)