Dealing with EOL characters in Cygwin Git and Git for Windows accessing the same repository
Asked Answered
S

1

7

My autocrlf is equal to true. In my cygwin-shell git status gives me a correct list of all my changes.

In Git Bash git status says I modified all files in the project. I also see this in Git GUI and the Changes-tab in IntelliJ.

How is this possible, and more importantly, how can I fix it?

Switzerland answered 16/10, 2014 at 14:50 Comment(7)
Git and Windows - not a match made in heaven, that's for sure!Denudation
What does git config --get core.autocrlf print?Microbalance
That's the problem, try set it to input in Cygwin, and see the result.Microbalance
Better consider stop using autocrlf, and use .gitattributes instead, see Dealing with line endings.Microbalance
Why mixing up 3 different git tools ? Use one and you are fine.Sewage
Yeah, Cygwin Git is much better IMO, especially it started to keep up recently.Microbalance
I'm finding that mintty's environment produces the right git behaviour, but my ssh environment is showing spurious modifications to files. I wish it was as simple as changing an environment variable but I can't figure out which one.Caffey
D
7

Cygwin Git "sees the world" as if it runs on a POSIX platform—thanks to the emulation provided by Cygwin. Contrary to this, Git for Windows is a native Windows program which does not use any emulation and tries to be as close to Windows standards (however idiotic) as possible. What this leads to is that for Cygwin Git, LF is the standard EOL character, while for Git for Windows, the native EOL sequence is CRLF. So both tools see the world differently, and that explains what you observe. Please read this recent thread for more info (and especially this message).

In either case, consider setting core.autocrlf to false anyway to avoid headaches bound to this "magic". I'm using GfW solely, and in the end switched that setting to false (it defaults to true) for good.

You might also find the extremely well commented .gitattributes file from the Mono project to be interesting to study.

Danica answered 16/10, 2014 at 15:23 Comment(4)
Ok, thanks! Several questions: (1) So you suggest setting autocrlf to false? (2) Any idea if there's somehow a way to have a GUI representation of git using cygwin? I sometimes have to do complex stages/commits where adding all modified files is not an option.Switzerland
@ArthurC, sorry for the long delay. 1) Yes, switching it to false will turn off any magic related to EOL sequences which should make Gits on both sides have the same idea w.r.t. EOLs. You then could force using CRLFs for certain (or all) files via .gitattributes. Or, if possible, make sure you're using text editors which have no problems with sole LFs as EOLs (Emacs and Vim are two examples). 2) I beleive Cygwin has builds of Tcl/Tk and hence stock Git's GUI tools, gitk and git gui should be available there.Danica
@ArthurC, 2), continued. Note that it's perfectly possible to do fine-grained staging using command-line tools only: git add can be used to stage any selected file, and git add --patch can be used to stage selected hunks of the changes that would be staged if you would do unadorned git add. The changes can also be selectively undone via git reset --patch and git checkout --patch: the former unstages the changes from the index while the latter does the same to the work tree. Not that I advise you against using git gui et al, just showing they do nothing special plain Git can't.Danica
Thanks kostix, but I'm taking another route. Uninstalled every git on my machine, installed msysgit and autocrlf=true. My problems are gone. A gui is handy for me because if I have 70 files I want to commit and 9 not, doing manually git add is really not efficient.Switzerland

© 2022 - 2024 — McMap. All rights reserved.