4

I've been trying a lot of different configurations to try to get git to stop this. I have a local file that has LF (not CRLF) line endings in the source repo:

$ cat -vT  Source/watchr.bat
echo OFF
echo ==========================================================
echo ==========================================================
echo The "watchr" command is deprecated.
echo The new command is sidekick.bat
echo " _
echo "| |
echo "| |_ _   _ _ __   ___

Note: no ^M, so there are no CRs in there. This is one of about 80 files, so a commit will create massive needless churn in the git history.

OK now look at git diff:

$  gd -R  Source/watchr.bat
+echo OFF^M
+echo ==========================================================^M
+echo ==========================================================^M
+echo The "watchr" command is deprecated.^M
+echo The new command is sidekick.bat^M
+echo " _                      ^M
+echo "| |                    ^M
+echo "| |_ _   _ _ __   ___ ^M

Argh, ^M on every line. Why? How?

The settings:

$ git config --global core.autocrlf
true

$ git config  core.autocrlf
false

$ cat -vT .gitattributes
# Set default behavior to automatically normalize line endings.
* text=

Changing the settings to input (or false) and auto (gitattributes) has no effect, git still wants to insert a CR into the watchr.bat file. Gitconfig in my home dir is also autocrlf = true. How do I get git to stop doing this?

Platform: git version 1.9.5.msysgit.0, Windows 7.

jcollum
  • 40,207
  • 47
  • 175
  • 294

2 Answers2

3

You should try:

git config --global core.autocrlf false

(That is what I recommend in "Git on Windows (msysgit) - Unix or DOS line termination")

Check also the local config:

git config core.autocrlf false

Make sure you don't have a .gitattribute with a core.eol directive which could also add \r\n eol.

Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
1

The solution to this was to eliminate .gitattributes. I had tried commenting out * text=auto in .gitattributes but that apparently wasn't "seen" by git. My coworker eliminated that file, pushed and then I pulled it and suddenly the "add a bunch of CRs everywhere" behavior went away.

I looked for a way to get git to see the newly changed .gitattributes (the local edits I made). Couldn't find any git command that would do that, so I had to assume git would check that file anytime it did a diff. Seems that that is not the case.

Perhaps this is a bug in git on Windows (since file watchers are dicey in Windows).

jcollum
  • 40,207
  • 47
  • 175
  • 294