In my project, the build result is a ZIP archive containing a .jar, several HTML files, a bash script, and a Windows .cmd file.
Now, I would like to add the Windows .cmd file to git, keeping the Windows.style CRLF line format. The rest of the project is Linux-style LF.
I have found several questions about CRLF in git, but all of the answers were about
[core] autocrlf = true
but that does not match my needs, as I do not want to have the whole project as CRLF, only this one Windows .cmd file (maybe very few more in future).
So, how can I tell git to keep CRLF only for handpicked files ?
text eol=crlf Git will always convert line endings to CRLF on checkout. You should use this for files that must keep CRLF endings, even on OSX or Linux. text eol=lf Git will always convert line endings to LF on checkout. You should use this for files that must keep LF endings, even on Windows.
Whereas Windows follows the original convention of a carriage return plus a line feed ( CRLF ) for line endings, operating systems like Linux and Mac use only the line feed ( LF ) character. The history of these two control characters dates back to the era of the typewriter.
--renormalize. Apply the "clean" process freshly to all tracked files to forcibly add them again to the index. This is useful after changing core.autocrlf configuration or the text attribute in order to correct files added with wrong CRLF/LF line endings.
Try file -k Short version: file -k somefile. txt will tell you. It will output with CRLF line endings for DOS/Windows line endings. It will output with CR line endings for MAC line endings.
You can use .gitattributes
, an entry such as:
*.cmd eol=crlf
This will ensure that the file is checked out with windows line endings even in clones that would normally use unix line endings,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With