简体   繁体   中英

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

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 ?

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM