Branch-specific configuration file maintenance with git

前端 未结 1 707
予麋鹿
予麋鹿 2021-01-06 23:35

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, <

相关标签:
1条回答
  • 2021-01-07 00:31

    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".

    0 讨论(0)
提交回复
热议问题