使用git进行分支特定的配置文件维护 [英] Branch-specific configuration file maintenance with git
问题描述
可以说有两个问题,一个问题让我困惑很久,因为我无法找到很好的,或多或少的通用解决方案。 git分支可用,
现在,问题出现了 - 如何按照需要的方式在git存储库中维护特定于分支的配置。常见的解决方案之一是在git中使用'template'配置文件,符号链接和忽略特定分支的具体内容,如
$ cat .gitignore | grep conf
/concrete.conf
$ ls -l * .conf
lrwxrwxrwx 1 1000 100 12月29日10:23 concrete.conf - > generic.conf
-rw -r - r-- 1 1000 100 0 Oct 29 10:16 generic.conf
打开并调整
- 支持每个git分支单独的配置文件,并且
- 保持由git管理的特定于分支的配置文件同时
甚至有可能吗?可能(实际上,更喜欢由其他人提供文件,但它并不相关......)
到目前为止我所想到的最好的是使用合并后钩子来调整每个分支配置本身
关于解决问题的任何建议描述?
PS:* nix特定的建议(即使用符号链接/硬链接)的建议是绝对好的,我确实有任何兴趣M $ targets
这是可能的,并且不涉及符号链接。
您不是版本 my.config
,而是模板文件 my.config.tpl
,和一个值文件(包含每个分支的值)
prod.conf
dev.conf
然后,您可以使用
(图片来源于定制Git - Git Attributes ,来自 Pro Git book )
脚本生成 my。通过将占位符值替换为
b $ b您可以通过以下方式了解当前分支名称: < branch.conf>
文件的值,可以在每次结帐分支时使用config
branch = $(git rev-parse --symbolic - abbrev-ref HEAD)
生成的实际 my.config
仍然被忽略(由 .gitignore
)。
这意味着您的实际工作树不会变脏。
污迹脚本选择正确的值文件,生成正确的 web.config
根据模板在 git checkout
过程中应用了涂抹脚本。
查看分支之间的git smudge / clean filter 的完整示例。
Here is a question keeps me puzzled for a long time as I cannot find nice and more-or-less universal solution to it.
Lets say there are two git branches available, production
and dev
; each uses it's own configurable parameters for some tasks (i.e. credentials, build path, test/deployment scripts switches et cetera). Same time implementation scripts & code is common for both branches.
Now, the problem arises is - how to maintain branch-specific configuration within git repository the way required. One of common solutions out there is to use 'template' configuration file within git, symlinking and ignoring the concrete for specific branch, like
$ cat .gitignore | grep conf
/concrete.conf
$ ls -l *.conf
lrwxrwxrwx 1 1000 100 12 Oct 29 10:23 concrete.conf -> generic.conf
-rw-r--r-- 1 1000 100 0 Oct 29 10:16 generic.conf
breaking and adjusting concrete.conf
on development box next. Yet not a solution I'm in pursuit for.
My requirements (ok, wishes) are:
- support separate configuration file per git branch, and
- keep branch-specific configuration file managed by git same time
Is it even possible? Could be (actually, preferred to be file sourced by some other one, but it's none related...)
The best that has came to my mind so far is to use post-merge hooks to adjust per-branch configuration per se from some other source ignored by git, but it stinks from the very beginning.
Any suggestions on solution of problem described ?
PS: *nix-specific suggestions (i.e. using symlinks/hardlinks) suggestions is absolutely fine, I do do have any interest in M$ targets
It is possible, and does not involve symlinking.
You do not version my.config
, but a template file my.config.tpl
, and a value file (with values for each branches)
prod.conf
dev.conf
Then, you can use a content filter driver, using .gitattributes
declaration.
(image from "Customizing Git - Git Attributes", from "Pro Git book")
The script generate my.config
file by replacing placeholder values with the values of the <branch.conf>
file, each time you checkout a branch.
You can know about the current branch name with:
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
The generated actual my.config
remains ignored (by the .gitignore
).
That means your actual working tree does not get "dirty".
The smudge script selects the correct value file and generates the correct web.config
based on the template the smudge script is applied on during a git checkout
.
See a complete example at "git smudge/clean filter between branches".
这篇关于使用git进行分支特定的配置文件维护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!