Git: convert carriage return \r to new line \n with git hook?

后端 未结 2 516
挽巷
挽巷 2021-02-15 17:00

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

相关标签:
2条回答
  • 2021-02-15 17:35

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

    0 讨论(0)
  • 2021-02-15 17:37

    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.

    0 讨论(0)
提交回复
热议问题