2

I know this question has been asked a hundred times, but none of the answers are ever exactly satisfactory.

I have a lot of tools (eg protoc protobuf compiler) which seem to one day spit out \r and the next \r\n so I can never have the files checked out the right way for every one of my developers.

And after they run the code generation step every file looks dirty because line endings were invariably changed.

Rather than controlling both how the file is checked in/out for line endings, and the code generators settings; I would like to be able to quickly revert every file that is a line end only change after I run my code generation script.

----------------------UPDATE------------------------------

I have not yet found a totally satisfactory solution, but I have found the root of my problem.

My tool is generating \n but git is checking thing out in \r\n on windows.

To cope with this I have set the attributes for the files as such: echo "*.pb.h text eol=lf" >>.gitattributes

Note I tracked some of this down using git ls-files --eol

if you continue running into the issue even after this you may want to run git add --renormalize .

See: 'git status' shows changed files, but 'git diff' doesn't

Techniquab
  • 843
  • 7
  • 22
  • Do you have your `autocrlf` setting set to true ? doesn't it take care of files that only differ on line endings ? – LeGEC Sep 30 '20 at 16:07
  • I have autocrlf to be on. To be honest no amount for reading the git documentation can make this feature make sense to me! However my understanding is that the auto feature works by switching endings as appropriate during commit/check out. This still means they are checked out in a particular state and your tools may not match that state. The setting does not ignore line ending only, if I could do that or roll them all back I would be happy. – Techniquab Sep 30 '20 at 16:11
  • Can you test the following : change line endings in a file (through an editor), then check `git status`. Does the file show up ? (it shouldn't) – LeGEC Sep 30 '20 at 17:25
  • I replaced all \r\n to \n in my file. `git status` indicates the file has changed. `git diff` indicates `warning: LF will be replaced by CRLF in version.json. The file will have its original line endings in your working directory. ` – Techniquab Sep 30 '20 at 17:32
  • You need the *tool* to behave consistently. Suppose tool T generates \r\n on even-numbered seconds, and \n-only on odd-numbered seconds. Then the output from T will depend on the exact second at which you run it. Git will correctly identify the output as different, if it's different. Make the *tools* behave first, then worry about making *Git* behave. – torek Sep 30 '20 at 23:27
  • 1
    I understand git is working as designed. And if it were my tool and just me I would make that tool behave. But it’s a bunch of tools across multiple developers and they somehow never agree on line endings. I’m no asking git to do anything different. I am just asking for a way (utility, script, whatever) to find all files that differ only in line endings and automatically check them out clean. – Techniquab Oct 01 '20 at 00:39

0 Answers0