I know this question is old, but just in case someone is still looking for an answer...
First, you have to make sure that core.autocrlf
is false
in your global and local config.
Then to force git to convert to CRLF, you can use a filter defined like this :
In your local config
file (.git\config) :
[filter "crlf"]
clean = unix2dos
And you can use it by adding a filter for certain files in the attribute
file (.git\info\attributes) :
*.txt filter=crlf
This filter makes use of the command unix2dos which comes with Git for Windows and could already be available if you are on Linux. Otherwise, you can install it or use an alternative command like sed -i -e 's/\r//g'
(this command works well assuming that you don't have any Mac line endings in your files).
What about running the filter on all files like this?
* filter=crlf
This could work, but I haven't used it in a large repo, so I can't guarantee that it won't affect performance or that there is no risk of corrupting binary files.
Luckily, unix2dos
has some checks in place to detect binary files and won't make any changes to them if they are detected as binary. I tried to run it on a PNG and got:
unix2dos: Binary symbol 0x1A found at line 2
unix2dos: Skipping binary file fff.png
You might need to keep an eye open if some files aren't detected properly, however.