使用代码分发 git 配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2333424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Distributing git configuration with the code
提问by nraynaud
In trying to standardise the platform for the developers, one of my needs would be to commit the .git/config
so that everybody have the same CRLF config without forgetting to set it by hand.
在尝试为开发人员标准化平台时,我的需求之一是提交,.git/config
以便每个人都拥有相同的 CRLF 配置,而不会忘记手动设置。
How do I set this up?
我该如何设置?
I'm a bit concerned by all this negativity against autocrlf
. Why not remove this feature if it doesn't work? Either the makers of this feature are misunderstood or they made a failed experiment with it and it should be removed to stop more people from wasting their time (reading the obscure man page, asking questions, people answering those questions etc.).
我对所有这些针对autocrlf
. 如果它不起作用,为什么不删除此功能?要么这个功能的创造者被误解了,要么他们做了一个失败的实验,应该删除它以阻止更多的人浪费时间(阅读晦涩的手册页,提出问题,人们回答这些问题等)。
回答by VonC
I have always found the autocrlf
config property problematic.
(as expressed in my answer Git 1.6.4 beta on Windows (msysgit) - Unix or DOS line termination)
我一直发现autocrlf
config 属性有问题。(如我的回答Git 1.6.4 beta on Windows (msysgit) - Unix or DOS line terminate 所示)
- it not only make some merges tricky
- it can vary depending on the shell used within one environment
- it also has issue with git status
- and with svn import.
- 它不仅使一些合并变得棘手
- 它可能因一种环境中使用的外壳而异
- 它也有git status 的问题
- 并使用svn import。
Note: msysgit issue 538for setting it to true (which is the default value set by the msysgit installer), but I am not convinced.
注意:msysgit 问题 538将其设置为 true(这是 msysgit 安装程序设置的默认值),但我不相信。
I would prefer one of the three following solutions for:
我更喜欢以下三种解决方案之一:
- configuring one end-of-line style
- making that configuration propagate through the different Git repos
- 配置一种行尾样式
- 使该配置通过不同的 Git 存储库传播
First: git config --global core.autocrlf false
Then:
第一:git config --global core.autocrlf false
然后:
1. Using the new config setting core.eol
(1.7.2+)
1. 使用新的配置设置core.eol
(1.7.2+)
Sets the line ending type to use in the working directory for files that have the text property set.
Alternatives are 'lf
', 'crlf
' and 'native
', which uses the platform's native line ending.
The default value is native.
设置在工作目录中使用的行结束类型,用于设置了 text 属性的文件。
替代方案是“lf
”、“crlf
”和“native
”,它们使用平台的本机行尾。
默认值为本机。
2. a checkout/checking .gitattribute
.
See gitattributesman page:
crlf
or core.autocrlf
is the way to record in a .gitattributes
file what is was previously a local config attribute.
2.结帐/检查.gitattribute
。请参阅gitattributes手册页:
crlf
或者core.autocrlf
是在.gitattributes
文件中记录以前是本地配置属性的方法。
You can add checkout/checkin attributeslike:
您可以添加结帐/签入属性,例如:
*.vcproj text eol=crlf
*.sh text eol=lf
3. a git attribute filter driverwhich can:
3. 一个git 属性过滤器驱动程序,它可以:
- enforce any kind of formatting standard you may want to set
- apply those standards to certain files/directories
- be recorded as a config file (
.gitattributes
) able to be pushed anywhere.
- 强制执行您可能想要设置的任何类型的格式标准
- 将这些标准应用于某些文件/目录
- 记录为配置文件 (
.gitattributes
),可以推送到任何地方。
回答by Jason Axelson
If you're using a Unix family operating system I would recommend just creating a symbolic link.
如果您使用的是 Unix 系列操作系统,我建议您只创建一个符号链接。
ln -s .git/config git-config
git add git-config
git commit -m "Now tracking git config file"
回答by kenorb
The .git/config
can be overridden locally by ~/.gitconfig
.
该.git/config
可以通过覆盖在本地~/.gitconfig
。
So as part of the build, Makefile or provision script, you can propose the change for users into their ~/.gitconfig
, or load local script .gitconfig
via git config
.
因此,作为构建的一部分,Makefile文件或提供脚本,可以提出用户更改到他们~/.gitconfig
,或者加载本地脚本.gitconfig
通过git config
。
For example, create new .gitconfig
with some settings, and load it by:
例如,.gitconfig
使用一些设置创建新的,并通过以下方式加载它:
git config --local include.path "/path/to/.gitconfig"
or ask users to have in their ~/.gitconfig
these lines:
或要求用户在他们的~/.gitconfig
这些行中:
[include]
path = .gitconfig
If you're using Vagrant as part of your code distribution, you may load git config from Vagrantfile
by:
如果您使用 Vagrant 作为代码分发的一部分,您可以Vagrantfile
通过以下方式加载 git config :
system('GIT_TRACE=1 git config --local include.path "$(git rev-parse --show-toplevel)/git/gitconfig"');
then commit your git config in git/gitconfig
, so each time when users run provisioning of their VM, this file would be loaded automatically for their git on host machine (e.g. to enforce core.filemode
to be disabled, so Windowswon't have any issues with file permissions).
然后提交你的混帐配置git/gitconfig
,所以每个用户在运行其置备VM的时候,这个文件将被自动地为他们的主机上的git加载(如强制core.filemode
被禁用,所以视窗不会与文件权限的任何问题) .
To force line endings for users, you should use .gitattributes
instead which should work out-of-box. Sample syntax to use Unix-like line endings (LF
):
要强制用户使用行结尾,您应该.gitattributes
改用 which 应该是开箱即用的。使用类 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 (not recommended).
#* 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
回答by METAJIJI
May be a better way to use the hardlink:
可能是使用硬链接的更好方法:
In *nix or OS X system:
在 *nix 或 OS X 系统中:
ln .git/config git-config
git add git-config
git commit -m "Now tracking git config file"
In Windows on NTFS-filesystem System:
在 NTFS 文件系统系统上的 Windows 中:
mklink /H git-config .git\config
git add git-config
git commit -m "Now tracking git config file"
But we must remember that when cloning project to apply the settings to perform the reverse procedure:
但是我们必须记住,在克隆项目时应用设置来执行相反的过程:
In *nix or OS X system:
在 *nix 或 OS X 系统中:
git clone FROM_PROJ_URL
rm .git/config
ln git-config .git\config
In Windows on NTFS-filesystem System:
在 NTFS 文件系统系统上的 Windows 中:
git clone FROM_PROJ_URL
del .git\config
mklink /H .git\config git-config