8

A fellow coder uses a Windows computer that is putting carriage returns everywhere in our source.

Is there a way to write a git hook that converts all \r\n to \n?

Note I haven't used git hooks before, so a little extra hand-holding might go a long way :)

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
maček
  • 76,434
  • 37
  • 167
  • 198

2 Answers2

11

The simplest thing is to set core.autocrlf to false on The Windows side.
(that way Git won't do any conversion and will keep the eol untouched).

On the unix side, a core.autocrlf set to true could help restore the proper eol.
As mathepic mentions in the comments, and as I described in this SO answer, since Git1.7.2, you can use core.eol (to native), keeping core.autocrlf to false.

Otherwise you can use a text driver or a filter driver with gitattributes files.
No hooks needed.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • VonC, perhaps i want `core.autocrlf` set to true? I **want** to remove the carriage returns. – maček Oct 04 '10 at 20:52
  • @macek: `autocrlf` might do the job on the Unix side, but I would recommend it to false on the Windows side, in order to not introduce all those crlf in the first place. I have edited my answer to reflect those choices and settings. – VonC Oct 04 '10 at 20:55
  • `core.eol` is the new way to do this, I think. – alternative Oct 04 '10 at 21:17
1

If they're using TortoiseGit, there's an option to do this for you, under Git->Config->Auto CRLF convert.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98