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

假如想象 提交于 2019-12-21 04:19:10

问题


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 :)


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3858931/git-convert-carriage-return-r-to-new-line-n-with-git-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!