Fixing mac/windows new lines with git pre-commit hook?

流过昼夜 提交于 2021-01-24 07:12:19

问题


In our office we working in a team of about 10 developers. Most of them have a Mac machines. Recently I've realise when I'm checking differences of my work (after changing only one line of code) almost each line is changed, but git diff shows you change is exactly same as original. After some research it's turned out to be a different new line. Before I do anything it's '\r\n' (CR+LF, 0x0D0A) and after my change all non Unix new lines (\r\n) are change to Unix one (\n).

I realize I could ask my colleagues to change their IDE settings, but I realize I can just prepare some script that need to be run each time they make a commit.

How can I run a bash script before git commit? How can use git pre-commit hook?


回答1:


Everything is explain on https://help.github.com/articles/dealing-with-line-endings and here http://git-scm.com/docs/gitattributes#_checking-out_and_checking-in

For Linux/Mac machines use

git config --global core.autocrlf input

For Windows machines use

git config --global core.autocrlf true

with this settings git will convert all \r\n line endings to \n before every commit.



来源:https://stackoverflow.com/questions/15223290/fixing-mac-windows-new-lines-with-git-pre-commit-hook

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