在Windows上使用Git smudge过滤器来创建本地配置文件

时间:2013-03-06 19:06:14

标签: git configuration

我正在尝试使用Git的涂抹/清洁过滤器来创建一个可能因环境而异的文件。

在我的回购中,我有以下文件:

/root/scripts/data.config.local
/root/scripts/data.config.staging
/root/scripts/data.config.production

在开发者计算机上进行结帐时,我希望将data.config.local文件作为“data.config”复制到/ root / scripts目录。

我的全局.gitconfig具有以下过滤器定义:

[filter "copyEnv"]
  clean = "rm -f c:\\code4x\\git\\rgpstage\\scripts\\gg_data.config"
  smudge = "cp c:\\code4x\\git\\rgpstage\\scripts\\gg_data.config.local c:\\code4x\\git\\rgpstage\\scripts\\gg_data.config"

我在这些过滤器上尝试了很多变体,包括将脚本移动到单独的脚本文件中。我的单独的涂抹脚本文件如下所示:

#! /usr/bin/bash
cp "C:\Code4X\GIT\rgpstage\scripts\gg_data.config.local" "C:\Code4X\GIT\rgpstage\scripts\gg_data.config"

无论我使用哪种方法进行过滤操作(内联或文件),我都会得到以下输出:

error: cannot feed the input to external filter c:\removeGGData
error: external filter c:\removeGGData failed
cp: cannot stat `C:\\Code4X\\GIT\\rgpstage\\scripts\\gg_data.config.local': No such file or directory
error: cannot feed the input to external filter c:\copyGGData
error: external filter c:\copyGGData failed 1
error: external filter c:\copyGGData failed

我在Windows 7上使用Git 1.8运行它。该文件确实存在,并在权限方面打开。

1 个答案:

答案 0 :(得分:1)

你似乎对涂抹和清洁过滤器有误解(顺便说一句 - 你的.gitattributes是什么样的?)。你正在做的是严重滥用该功能。这些过滤器用于过滤文件,在STDIN上传递给它们,并在STDOUT上返回过滤后的版本。绝对不应该有任何副作用。

因此,为了在不同的机器上实现不同的配置,我建议将它们全部放入同一个文件中并使用if语句包围它们,该语句使用来自涂抹过滤器的信息。有关详细信息,请参阅我的答案:https://stackoverflow.com/a/13616911/758345