regex - 从命令行使用 git 属性

标签 regex git attributes

我的存储库中有此配置:

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

当我这样做时git diff ...我得到了预期的结果。

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

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

我想做的是像这样运行脚本,并获得与属性存在相同的结果。我不想设置全局属性或将 .gitattributes 添加到我想要分析的 git 项目中。我不介意类似的事情

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

但我不知道如何获取 git 使用的 java 正则表达式。

最佳答案

来自git帮助配置:

core.attributesfile

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 调用,如下所示:

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

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

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

关于regex - 从命令行使用 git 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18950604/

相关文章:

javascript - 正则表达式捕获组

regex - 正则表达式排除双字符

用于查找 3 次或更多次出现的正则表达式

javascript - 为什么我会在 HTML 和 CSS 中使用类而不是属性?

regex - 如何重新定义 "minibuffer"模式映射中的键?

svn - git-svn 和远程 git repo sync

git - 如何从git暂存区中删除文件?

git - 有没有办法使用 microdnf 将 git 安装到 RedHat ubi 8 最小图像中并解决安装 shadow-utils 的错误?

c# - ASP.Net MVC 2.0 : EditorFor setting name via attributes

macos - 如何在 Mac OS X 中删除文件上的 "extended attributes"?