使用git pre-commit挂钩修复mac/windows新行? [英] Fixing mac/windows new lines with git pre-commit hook?

查看:84
本文介绍了使用git pre-commit挂钩修复mac/windows新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的办公室中,我们由大约10个开发人员组成的团队工作.他们中的大多数人都拥有Mac机.最近,我意识到当我检查工作差异(仅更改一行代码后)时,几乎每一行都被更改,但是 git diff 显示您所做的更改与原始更改完全相同.经过一番研究,事实证明这是一条不同的新路线.在做任何事情之前,它都是'\ r \ n'(CR + LF,0x0D0A),在我更改之后,所有非Unix新行(\ r \ n)都更改为Unix一(\ n).

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

我意识到我可以要求同事更改他们的IDE设置,但是我知道我可以准备一些每次提交时都需要运行的脚本.

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.

如何在git commit之前运行bash脚本?如何使用git pre-commit hook?

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

推荐答案

http://git-scm.com/docs/gitattributes#_checking-out_and_checking-在

对于Linux/Mac计算机使用

For Linux/Mac machines use

git config --global core.autocrlf input

在Windows计算机上使用

For Windows machines use

git config --global core.autocrlf true

具有此设置的git将在每次提交之前将所有 \ r \ n 行尾转换为 \ n .

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

这篇关于使用git pre-commit挂钩修复mac/windows新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆