tags:

views:

581

answers:

4

I want to force git to checkout files under Windows using just LF not CR+LF. I checked the two configuration options but I was not able to find the right combination of settings.

I want it to convert all files to LF and keep the LF on the files.

Remark: I used autocrlf = input but this just repairs the files when you commit them. I want to force it to get them using LF.

Probably I wasn't so clear: the repository is already using LF but the files checked out using msysgit are using CR+LF and I want to forge msysgit to get them with LF: forcing Unix line endings.

>git config --list | grep crlf
core.autocrlf=input
+1  A: 

this is not what you want todo.

you want to check out all files, let it fix line endings and commit so that

For text files this is the right thing to do: it corrects line endings such that we have only LF line endings in the repository http://www.kernel.org/pub/software/scm/git/docs/git-config.html (save.crlf)

Rufinus
+3  A: 

The OP added in his question:

the files checked out using msysgit are using CR+LF and I want to forge msysgit to get them with LF

A first simple step would still be in a .gitattributes file:

*.txt -crlf

, to avoid any crlf conversion for files with correct eol.

See Best practices for cross platform git config?


But a second more powerful step involves a gitattribute filter driver and add a smudge step

alt text

Whenever you would update your working tree, a script could, only for the filees you have specified in the .gitattributes, force the LF eol and any other formatting option you want to enforce.
If the "clear" script doesn't do anything, you will have (after commit) transformed your files, applying exactly the format you need them to follow.

VonC
Surely it should be `-crlf` to prevent lf -> crlf conversion?
Charles Bailey
@Charles: thank you. Fixed.
VonC
One question: *.txt refers to all files with .txt extension or to all text files (non binary)? I cannot make a list with all kinds of file extension I will have in the project.
Sorin Sbarnea
@Sorin: all files with `.txt` extension. It is preferable to first establish this and test it on a specific group, before generalizing to *, and add a negative rule `!*.xyz ...` to exclude some few files from that rule.
VonC
A: 

I've said this before and I'll say it again: never set git to play with the line ending type.

If you need unix line endings on windows, use a decent editor. If your editor can't use unix line endings or can't be configured to save with unix line endings, then by definition it's not a decent editor, and you should use something else.

hasen j
Dear hasen, probably you missed the point in my question: I wasn't complaining about Editor, I do use only editors that are able to work with different line endings, like Notepad++. In this case the problem is within git itself.
Sorin Sbarnea
A: 

core.autocrlf=input is the right setting for what you want, but you might have to do a "git update-index --refresh" and/or a "git reset --hard" for the change to take effect.

With core.autocrlf set to input, git will not apply newline-conversion on check-out (so if you have LF in the repo, you'll get LF), but it will make sure that in case you mess up and introduce some CRLFs in the working copy somehow, they won't make their way into the repo.

kusma