从命令行使用git属性 [英] Using git attributes from command line

查看:114
本文介绍了从命令行使用git属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的仓库中有以下配置:

I have this configuration on my repo:

echo '*.java diff=java' >> .gitattributes

当我执行git diff ...时,我得到了预期的结果.

and when I do git diff ... I get the expected results.

但是,我正在做一个脚本来分析其他git存储库,所以我通常这样做:

However, I'm doing a script to analyse other git repositories, so I usually do:

git --git-dir='/path/to/repo/.git' diff ...

我想做的就是像这样运行脚本,并获得与属性相同的结果.我不想设置全局属性或向要分析的git项目添加.gitattributes.我不会介意

What I would like to do is to run the script like that, and have the same results as if the attribute was present. I don't want to set global attributes or add a .gitattributes to the git project I want to analyse. I wouldn't mind something like

git --git-dir='/path/to/repo/.git' diff --word-diff-regex=<java-rexeg> 

但是我不知道如何获得git使用的Java正则表达式.

But I don't know how to get the java regex git uses.

推荐答案

来自git help config:

core.attributesfile

除了.gitattributes(按目录)和.git/info/attributes外,git还在此文件中查找属性(请参见gitattributes(5)).路径扩展的方式与core.excludesfile相同.其默认值为$ XDG_CONFIG_HOME/git/attributes.如果未设置$XDG_CONFIG_HOME或为空,则使用$HOME/.config/git/attributes.

In addition to .gitattributes (per-directory) and .git/info/attributes, git looks into this file for attributes (see gitattributes(5)). Path expansions are made the same way as for core.excludesfile. Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/attributes is used instead.

换句话说,您可以在$XDG_CONFIG_HOME/git/attributes处创建自己的属性文件,并将XDG_CONFIG_HOME传递给git调用,如下所示:

In other words, you can create your own attributes file at $XDG_CONFIG_HOME/git/attributes, and pass XDG_CONFIG_HOME to your git invocation like this:

XDG_CONFIG_HOME=config_dir git --git-dir='/path/to/repo/.git' diff ...

因为您可以精确控制XDG_CONFIG_HOME,所以它不是真正的全局性的-您可以即时完成.

Because you control exactly what is XDG_CONFIG_HOME, it would not be truly global - you can do it totally on a fly.

或者,相反,在$HOME/.config/git/attributes中创建全局git属性文件可能更简单.

Or, it may be simpler to create global git attributes file in $HOME/.config/git/attributes instead.

这篇关于从命令行使用git属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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