gitcore.autocrlf

How to force git commit with CRLF?


If I use autocrlf, it looks like here

                     push    clone
1) true:             x -> LF -> CRLF
2) input:            x -> LF -> LF
3) false:            x -> x -> x

but I want git auto commit with CRLF:

x -> CRLF (if I use LF, it will commit with CRLF)

Can I do it?

Thank in advance !!!

Edit: I think git doesn't support it, so I force change lf to crlf with crlf.


Solution

  • You can at least make sure the file are checked out correctly, with a eol directive in a .gitattributes file:

    # Declare files that will always have CRLF line endings on checkout.
    *.sln text eol=crlf
    

    This setting forces Git to normalize line endings for this file on checkin and convert them to CRLF when the file is checked out.

    That, combined with git config --global core.autocrlf false would make sure your files are usable in your working tree.


    I want when I commit file with CRLF or LF, git change it to CRLF.

    With the setting above, that does not seem to be possible, as the default normalization being always to convert of LF on checkin.
    That only is to make sure your files are checked out with the right eol (end-of-line).

    But if you want to force crlf on checkin, you will need to do so manually.
    Try:

    git config --global core.autocrlf false
    

    Make sure you do not have any core.eol or text eol directive in any .gitattributes files (to avoid any "renormalization")

    And do a unix2dos on any file checked out with the wrong eol.

    Finally, add and commit: those files with CRLF should still be checked in with CRLF.