将忽略的配置文件添加到git repo中作为示例 [英] Add ignored config file to git repo as sample
问题描述
我有一个我正在处理的应用程序的存储库,其中包含一个配置文件。目前,我使用 .dist
扩展名进行分发,并让用户在编辑文件之前重命名文件。
nate:〜/ myAwesomeApp%git ls-files
.gitignore
README
config.dist
glorious_support_lib.p
bestProgramEvar.f90
这很好,很实惠,实际的配置被忽略了。
nate:〜/ myAwesomeApp%cat .gitignore
config
然而,如果我只能以真实名称分发该配置文件并准备编辑,而忽略该配置文件,那么它将会是甜蜜存储库的克隆副本具有功能分布,并且不会被覆盖,破坏或以其他方式调用,从而用户不必担心推送或发布他们的超级秘密配置详细信息通过一个意外的 git commit -a -m'hurrrr derp! oopsies!'&& git push
有没有这样做的方法?让git保留一个原始版本的文件被克隆出来,但之后被忽略?
我确信这有之前被问过,但在我的生活中,我的google-fu失败了。把学校放在很深的地方,就这样。
您也可以版本和发布:
.gitattributes
文件声明 过滤驱动程序 (仅限于'config.dist')
config
文件)的smudge脚本
现在我们稍微介绍一下过滤器驱动程序(它是关于修改文件的内容,) 。但它可以工作。
.gitattributes
应该包含:
config.dist filter = generateConfig
您可以注册您的涂抹脚本(在创建/更新时在结帐步骤中应用)工作目录):
git config --global filter.generateConfig.smudge / path / to / generateConfig
I have an repository for an app that I'm working on that includes a configuration file. Currently, I distribute with a .dist
extension, and have the user rename the file before editing it.
nate:~/myAwesomeApp% git ls-files
.gitignore
README
config.dist
glorious_support_lib.p
bestProgramEvar.f90
This is fine and dandy, and the actual config is ignored.
nate:~/myAwesomeApp% cat .gitignore
config
It would be sweet, however, if I could just distribute that config file under its real name and ready-to-edit, while leaving it ignored so that a newly cloned copy of the repository has a "functional" distribution, and it is not overwritten, clobbered, or otherwise molested, and such that users don't have to worry about pushing or publishing their super-secret configuration details to the interwebs via an unintended git commit -a -m 'hurrrr derp! oopsies!' && git push
Is there a way of doing this? Of having git keep around a single original version of the file that gets cloned out, but is thereafter ignored?
I'm sure this has been asked before, but for the life of me, my google-fu has failed. Lay the schoolin' on deep, SO.
You can also version and distribute:
- a
.gitattributes
files declaring a filter driver (for only 'config.dist') - a smudge script which will detect that content and generate the final (and private, as in "non-versioned"
config
file)
Now that is bending a bit what a filter driver is about (it is about modifying the content of a file, regardless of its "state", i.e its full path and name). But it can work.
The .gitattributes
would contain:
config.dist filter=generateConfig
And you can register your smudge script (applied during the checkout step when creating/updating the working directory) like:
git config --global filter.generateConfig.smudge /path/to/generateConfig
这篇关于将忽略的配置文件添加到git repo中作为示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!