在试图为开发人员标准化平台时,我的需求之一是提交.git/config
,以便每个人都拥有相同的CRLF配置,而不会忘记手动设置它。使用代码分发git配置
我该如何设置?
对于autocrlf
,我有点担心所有这些消极情绪。如果它不起作用,为什么不删除此功能?要么这个功能的制造者被误解了,要么他们做了一个失败的实验,它应该被删除以阻止更多的人浪费他们的时间(阅读不明确的手册页,提出问题,回答这些问题的人等)。
在试图为开发人员标准化平台时,我的需求之一是提交.git/config
,以便每个人都拥有相同的CRLF配置,而不会忘记手动设置它。使用代码分发git配置
我该如何设置?
对于autocrlf
,我有点担心所有这些消极情绪。如果它不起作用,为什么不删除此功能?要么这个功能的制造者被误解了,要么他们做了一个失败的实验,它应该被删除以阻止更多的人浪费他们的时间(阅读不明确的手册页,提出问题,回答这些问题的人等)。
我一直发现autocrlf
config属性有问题。
注意:msysgit issue 538设置它为true(这是由msysgit安装程序设置的默认值),但我不相信。
我宁愿为以下三个解决方案之一:
1.使用新的config setting core.eol
(1.7.2+)
将行结束类型设置为使用i n设置文本属性的文件的工作目录。
替代品是'lf
','crlf
'和'native
',它使用平台的本地行结尾。
默认值是本机。
2.a checkout/checking .gitattribute
。 请参阅gitattributes手册页: crlf
或core.autocrlf
是在.gitattributes
文件中记录以前是本地配置属性的方法。
3。一个git attribute filter driver可以:
.gitattributes
)能够在任何地方推。感谢您的回答。我想我收到关于autocrlf的混淆信息。我读过的地方git确实只在\ n模式下提交,它很好。我的一些开发人员正在使用Windows,而且由于世界上的每个人都可以读取crlf,所以我认为每个人的crlf都是最好的。但我们必须容纳似乎只喜欢cr的git。你怎么看 ? 我在审查属性的想法,我排除之前,因为我的理解是,它适用于每个文件的基础上,而不是存储库范围内的作品。也许我错了。 – nraynaud 2010-03-01 11:11:55
@narynaud:个人而言,我喜欢''\ n'',而且我不想改变关于eol的暗示。但是,如果你强制执行一种eol风格,'.gitattributes'真的很有趣,因为你可以将它应用到所有仓库,或者只应用到仓库中的特定部分。 – VonC 2010-03-01 11:19:09
如果我在项目根目录中定义了 * + crlf ,我想我会用我的png图片去下地狱? 我怎么说“如果你认为这是文字,然后做crlf,否则,做二元”。我想避免自己做出艰难的决定,系统擅长这种猜测和调试,错误会非常困难。 – nraynaud 2010-03-01 13:37:15
如果您使用的是Unix系列操作系统,我会建议您只创建一个符号链接。
ln -s .git/config git-config
git add git-config
git commit -m "Now tracking git config file"
这是一个聪明的的想法,我们混合Windows/Mac/Linux。但也许git可以使用Windows链接的东西,我会尝试谷歌。 – nraynaud 2010-02-25 11:43:35
它不起作用,在Unix上git甚至没有看到配置文件的变化。 – nraynaud 2010-02-26 11:28:33
那么如果你在unix上它应该反过来工作 mv .git/config git-config; cd .git; ln -s ../git-config config; 012 ..,..,.. ..。 git add git-config; git commit -m“现在跟踪git配置文件”; – 2010-03-19 21:05:41
可能是使用一个更好的方式hardlink:
在Unix或者OS X系统:
ln .git/config git-config
git add git-config
git commit -m "Now tracking git config file"
在Windows上的NTFS文件系统系统:
mklink /H git-config .git\config
git add git-config
git commit -m "Now tracking git config file"
但我们必须记住,在克隆项目时应用设置来执行反向过程:
在Unix或者OS X系统:
git clone FROM_PROJ_URL
rm .git/config
ln git-config .git\config
在Windows上的NTFS文件系统的系统:
git clone FROM_PROJ_URL
del .git\config
mklink /H .git\config git-config
的.git/config
可以通过~/.gitconfig
局部覆盖。
因此,作为构建的一部分,Makefile文件或提供脚本,可以提出用户更改到他们的~/.gitconfig
,或通过git config
加载本地脚本.gitconfig
。
例如,创建一个新的.gitconfig
一些设置,并通过加载:
git config --local include.path "/path/to/.gitconfig"
或要求用户在他们的~/.gitconfig
这些行:
[include]
path = .gitconfig
如果您使用放浪作为代码分发的一部分,你可以通过以下方式从Vagrantfile
加载git config:
system('GIT_TRACE=1 git config --local include.path "$(git rev-parse --show-toplevel)/git/gitconfig"');
然后在git/gitconfig
中提交你的git配置,所以每当用户运行VM的配置时,这个文件就会自动加载到他们在主机上的git上。强制core.filemode
被禁用,所以Windows将不会有任何文件权限问题)。
要强制行结尾的用户,你应该使用.gitattributes
代替它应该工作外的框。语法示例使用类Unix行结尾(LF
):
# Drupal git normalization
# @see https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
# @see https://www.drupal.org/node/1542048
# Define text file attributes.
# - Treat them as text.
# - Ensure no CRLF line-endings, neither on checkout nor on checkin.
# - Detect whitespace errors.
# - Exposed by default in `git diff --color` on the CLI.
# - Validate with `git diff --check`.
# - Deny applying with `git apply --whitespace=error-all`.
# - Fix automatically with `git apply --whitespace=fix`.
*.css text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.html text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=html
*.js text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.json text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
# Auto-detect text files, ensure they use LF.
* text=auto eol=lf
# Define binary file attributes.
# - Do not treat them as text.
# - Include binary diff in patches instead of "binary files differ."
*.gz -text diff
参见http://stackoverflow.com/questions/2332349/best-practices-for-cross-platform-git-config:你可能有添加到这个类似问题的答案。 – VonC 2010-03-02 09:13:30
谢谢,但我对所有这些对autocrlf的否定性有点担心,为什么不删除这个功能,如果它不工作?这个功能的制造者或者被误解了,或者他们做了一个失败的实验,它应该被删除,以阻止更多的人浪费他们的时间(阅读不明确的手册页,提问,回答这些问题的人等)。 – nraynaud 2010-03-02 23:08:40