5

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 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Macs now use \n as line ending. I cannot find the source, but this is fact.
That's true en.wikipedia.org/wiki/Newline#Representations BUT seems some of my colleagues IDE is set to non-Unix line ending.
Windows users may want \n line endings too. In that case it's better to handle the conversion in a git hook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.