一位同事使用 Windows 计算机,在我们的源代码中到处都放回车符。
有没有办法写一个git钩子(Hook),把所有的\r\n
都转换成\n
?
注意 我以前没有使用过 git hooks,所以多加一些帮助可能会有很长的路要走:)
最佳答案
最简单的就是set core.autocrlf
to false在 Windows 端。
(这样 Git 就不会做任何转换,并且会保持 eol 不变)。
在 unix 端,将 core.autocrlf
设置为 true 可以帮助恢复正确的 eol。
作为mathepic在评论中提到,并作为I described in this SO answer , 从 Git1.7.2 开始,你可以使用 core.eol
(to native),保持 core.autocrlf
为 false。
否则你可以使用 text driver or a filter driver with gitattributes
files .
不需要 Hook 。
关于Git:使用 git hook 将回车符\r 转换为新行\n?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3858931/