问题
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