5

I know there are a ton of questions/answers similar to this one, however I could not find a specific answer to this problem. We are a .net shop and are using git.

I would like a way to ignore CRLF (^M) changes to files when doing a git status. While developing, other processes are occasionally modify files and injecting the CRLF, ultimately resulting in them showing as modified when a git status is done. I have the line "* text=auto" within my .gitattributes file in order to normalize line endings at checkout/commit but this is not what I am looking for. I have also tried to add the following to the git config (core.whitespace=cr-at-eol) but they still show as modified.

How do I tell git to ignore all changes to CRLF (^M)?

MrMiyagi
  • 61
  • 1
  • 4
  • Aren't those other processes that occasionally modify files doing anything besides injecting random `CR`s? – jthill Jun 11 '14 at 22:58

2 Answers2

3

You cannot ignore types of filechanges for git status. You can use .gitignore to ignore entire files. And you can use the various whitespace options to transform what is committed, what is highlighted (in red) or shown at all in the diff and commit views.

The reasons you cannot ignore these filechanges are:

  • Tracking filechanges is the entire point of version control.
  • Git represents file contents independent of path by using a SHA1 hash of the contents. Your ^M affects that SHA1 so that makes it unavoidably significant.

In short, you probably need to fix your other processes or develop clean-up post-processes. Alternatively you could use:

git diff-files --name-status --ignore-space-at-eol

This is not a perfect analogue of status proper, but it might be enough for your needs. For convenience, you can even build a git-alias'd "statusx" command by adding to your .gitconfig:

[alias]
    statusx = diff-files --name-status --ignore-space-at-eol

There are some additional whitespace options if that proves inadequate: --ignore-space-change and --ignore-all-space. See git diff --help for more detail.

Joe Atzberger
  • 3,079
  • 1
  • 18
  • 16
  • Hi Joe, I had a feeling that what I was asking for was impossible. Thank you for providing the clarification and some alternatives. In fact, we've just discovered the source of the these ^M changes as nuget so I am going to work that angle. Thanks again. http://pampanotes.tercerplaneta.com/2012/07/git-nuget-packages-and-windows-line.html – MrMiyagi Jun 13 '14 at 20:09
2

You can try and test the -crlf attribute in your .gitattributes file:

*.cs -crlf

The .gitattributes man page also mentions -text, but that would make your source files as binary (no diff).

Otherwise, core.eol are directives to use to control eol style.
It is more precise than core.autocrlf, which is presented here.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thanks for your reply! It is my understanding that the .gitattributes file only modifies(normalizes) files at commit time. I am looking for something that would ignore ^M changes to files when performing a git status. I also played with the core.eol and core.autocrlf settings but again I don't think this is the solution I am looking for. Perhaps I am asking git to do something that is impossible? Git status displays the difference between the index and the current HEAD. I would like a way to have git ignore only changes to involving ^M, and not show those changes when performing a git status. – MrMiyagi Jun 11 '14 at 21:49
  • 2
    @user3731545 the `-crlf` attribute is supposed to ignore eol during a `git status`. – VonC Jun 11 '14 at 21:52