将git config存储为存储库的一部分 [英] Storing git config as part of the repository

查看:90
本文介绍了将git config存储为存储库的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用过滤器在结帐期间对文件进行破解,如此处
现在问题是过滤器定义只存储在我的本地配置文件中:

  $ cat .git / config 
....
[filterdater]
smudge = /home/.../expand_date
clean = perl -pe \s / \\ \\\\ $日期[^ \\\\\\ $] * \\\\\\ $ / \\\\\\ \\\ $ Date \\\\\ $ / \

如果我的同事想从这个 Date 扩展中受益,他们需要复制我的过滤器定义。如果我改变它,我需要通知他们,等等。

那么我可以存储 .git / config 在仓库中,并使git使用它?

解决方案

有3个受支持的作用域 .gitconfig 文件: - system,--global,--local 。您还可以创建自定义配置文件,并将其包含在其中一个受支持的文件中。

您的需求自定义 - 是正确的选择。不要在 .git / config 中编写过滤器,而应将其保存在存储库根目录下的 .gitconfig 文件中:

 您的回购/ 

├──.git /
│├── config

├──.gitconfig

创建 .gitconfig 与您的过滤器并提交更改。然后你的同事会一直保持更新 - 但他们必须手动包含它。 无法通过git单独自动添加自定义配置文件,因为它会产生安全漏洞。

要将此配置应用于单个存储库,每个用户需要在 your-repo / :



pre $ g $ git config --local include.path ../.gitconfig

小心不要将个人资料储存在自订 .gitconfig 中,例如 user。* ,保留在你的全局 .gitconfig 中。


I'm using filters to mangle files during checkout like described here. Now the problem is that filter definition is only stored in my local configuration file:

$ cat .git/config
....
[filter "dater"]
        smudge = /home/.../expand_date
        clean = perl -pe \"s/\\\\\\$Date[^\\\\\\$]*\\\\\\$/\\\\\\$Date\\\\\\$/\"

If my coworkers want to benefit from this Date expansion, they need to copy my filter definition. And if I change it, I need to notify them, etc..

So can I store this filter definition part of .git/config in repository and make git use it?

解决方案

There are 3 supported scopes of .gitconfig file: --system, --global, --local. You can also create a custom configuration file, and include it in one of the supported files.

For your needs custom - is the right choice. Instead of writing your filter in .git/config you should save it in .gitconfig file in your repository root:

your-repo/
│
├── .git/
│   ├── config
│
├── .gitconfig
│

Create the .gitconfig with your filter and commit the changes. Then your colleagues will always keep it updated -- but they will have to include it manually. It is not possible to automatically include your custom configuration file through git alone, because it creates a security vulnerability.

To apply this configuration for a single repository, each user will need to run the following command in your-repo/:

git config --local include.path ../.gitconfig

Be careful not to store personal data in the custom .gitconfig, like user.*, keep those in your global .gitconfig.

这篇关于将git config存储为存储库的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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