2013-03-06 67 views
2

我正嘗試使用Git的塗抹/清除過濾器來創建一個可以根據環境而有所不同的文件。Windows上的Git塗抹過濾器來創建本地配置文件

在我的回購協議,我有以下文件:

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

當Checkout與開發人員的機器上時,我想data.config.local文件複製到/ root/scripts目錄作爲「data.config」。

我全球的.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

你似乎對smudge和clean filters有誤解(順便說一句 - 你的.gitattributes是什麼樣的?)。你在做什麼是嚴重濫用該功能。這些過濾器旨在過濾一個文件,並在STDIN上傳遞給它們,同時在STDOUT上返回一個過濾版本。這些製造商絕對不應該有任何副作用。

因此,爲了在不同的機器上實現不同的配置,我建議將它們全部放在同一個文件中,並用if語句將它們包圍起來,該語句使用來自污跡過濾器的信息。詳情請參閱我的答案:https://stackoverflow.com/a/13616911/758345