git - git config 中的 Shell 变量扩展

标签 git shell

我有一个 shell 变量,它指向我所有配置文件所在的目录。假设变量是使用 export RC=$HOME/rc 创建的。我在配置目录中有一个全局忽略文件:~/rc/globalgitignore

我的问题是,如何在我的 .gitconfig 文件中扩展 RC 变量?

我已经尝试过以下方法:

  • excludesfile = $RC/globalgitignore

  • excludesfile = !$RC/globalgitignore

  • excludesfile = !echo $RC/globalgitignore

  • excludesfile = !$(echo $RC/globalgitignore)

这些解决方案都不起作用。

如果我输入完整路径,唯一可行的方法是:excludesfile = ~/rc/globalgitignore,但是如果移动我的 rc 目录,我必须更改路径到不同的位置。

最佳答案

你不能。 git-config(1)不支持环境变量扩展,只支持有限的类型转换和路径扩展:

The type specifier can be either --int or --bool, to make git config ensure that the variable(s) are of the given type and convert the value to the canonical form (simple decimal number for int, a "true" or "false" string for bool), or --path, which does some path expansion (see --path below). If no type specifier is passed, no checks or transformations are performed on the value.

--path 的文档指出:

--path

git-config will expand leading ~ to the value of $HOME, and ~user to the home directory for the specified user. This option has no effect when setting the value (but you can use git config bla ~/ from the command line to let your shell do the expansion).

git-config(1) 中术语“扩展”没有出现在任何不同的上下文中。那么,鉴于在任何地方都没有记录此类功能,您是怎么想到应该这样做的呢?

为了扩展环境变量,您必须自己预处理 Git 配置文件,即通过创建模板文件,并在将文件复制到您的 $HOME 目录之前使用脚本扩展变量.

如果它是关于点文件管理的,那么就像所有人所做的那样:将它们放在一个目录中,然后从您的 $HOME 向该目录添加符号链接(symbolic link)。

关于git - git config 中的 Shell 变量扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11262010/

相关文章:

git - 在 Github 上,将 PR merge 到不同的分支

git - 为什么 checkout 有时会暂存一个文件?

linux - 我希望 shell 脚本可执行但不可读

linux - 我需要在一个终端中运行此命令 -> nc -l -p 80,并在第二个终端槽脚本中运行此命令 -> fusion -k 80/tcp

shell - fish shell 。如何检查变量是否设置/为空?

git - 使用 SSH 为 Phabricator 配置 Git

git - 我可以将本地 Git 存储库安全地移动到硬盘驱动器中的其他位置吗?

git - Visual Studio Team Services 代码未与 Azure 网站同步 - git

arrays - Linux 控制台中的 MongoDB 命令带有 --eval (print

linux - 如何 'grep'连续流?