Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - how to keep CRLF endings for specific files only?

Tags:

git

newline

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 ?

like image 988
Markus N. Avatar asked Oct 23 '13 19:10

Markus N.


People also ask

How do you preserve line endings in git?

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.

Should I use CRLF or LF?

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.

What is git Renormalize?

--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.

How do you find the end of a line file?

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.


1 Answers

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,

like image 88
CB Bailey Avatar answered Sep 21 '22 22:09

CB Bailey