我可以在 .gitignore 脚本中使用 macros/variables 吗?
Can I use macros/variables in a `.gitignore` script?
有什么方法可以在 .gitignore
脚本中使用宏或变量 (à la bash
)? gitignore docs don't mention anything along those lines, but I figured I'd ask just in case there's some undocumented features and/or cool workarounds. A few people have asked 关于在 .gitignore
中使用环境变量,但我想知道是否有任何支持类似宏或类似 var 的东西。
用例
我有一个正在对其目录进行重构的存储库 structure/paths。在我的 .gitignore
脚本中,某些路径以多种模式使用,因此如果能够按照以下方式在其中添加一些内容会很好:
# set a variable
UNSTABLE_PATH=foo/bar
# use the variable in some patterns
$UNSTABLE_PATH/test_data
$UNSTABLE_PATH/test_output
是的,在你说之前,我知道巧妙地使用 glob and/or 递归 glob 可能涵盖我的用例。如果还有一些简单的变量支持就好了。虽然想到它,但我也会找到一种方法来使 git mv
命令重写 .gitignore
.
中的匹配路径
好吧,我将直接跳到评论中语义辩论的结尾,然后就此结束:
.gitignore
不是脚本,它是模式列表。正如您所期望的那样,它不支持变量。
如果你真的需要这种能力,我会从 sass 或更少的人那里得到提示:编写你自己的 "ignore rules with extended syntax" 文件并编写一个脚本将其归结为适当的.gitignore
个文件。
但是如果你想要我的两分钱,这看起来像是另一种情况,可以通过将一些东西移出你的工作树来解决,这样工作树就可以只是一个工作树。
有什么方法可以在 .gitignore
脚本中使用宏或变量 (à la bash
)? gitignore docs don't mention anything along those lines, but I figured I'd ask just in case there's some undocumented features and/or cool workarounds. A few people have asked 关于在 .gitignore
中使用环境变量,但我想知道是否有任何支持类似宏或类似 var 的东西。
用例
我有一个正在对其目录进行重构的存储库 structure/paths。在我的 .gitignore
脚本中,某些路径以多种模式使用,因此如果能够按照以下方式在其中添加一些内容会很好:
# set a variable
UNSTABLE_PATH=foo/bar
# use the variable in some patterns
$UNSTABLE_PATH/test_data
$UNSTABLE_PATH/test_output
是的,在你说之前,我知道巧妙地使用 glob and/or 递归 glob 可能涵盖我的用例。如果还有一些简单的变量支持就好了。虽然想到它,但我也会找到一种方法来使 git mv
命令重写 .gitignore
.
好吧,我将直接跳到评论中语义辩论的结尾,然后就此结束:
.gitignore
不是脚本,它是模式列表。正如您所期望的那样,它不支持变量。
如果你真的需要这种能力,我会从 sass 或更少的人那里得到提示:编写你自己的 "ignore rules with extended syntax" 文件并编写一个脚本将其归结为适当的.gitignore
个文件。
但是如果你想要我的两分钱,这看起来像是另一种情况,可以通过将一些东西移出你的工作树来解决,这样工作树就可以只是一个工作树。