且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用不同的配置文件为开发和测试分支设置Git

更新时间:2022-10-17 22:10:24

你想在你的分支中有不同的wp-config文件,但是当你将一个分支合并到master中时,它们不应该被合并。



我能想到三种解决方案到你的问题:


  1. 你可以把它们放到你的分支中,而不是把它们合并到master中,而是采用cherry-picking。

  2. 您可以将它们放入分支并提交更改ect文件。 您可以将文件完全保留在回购库中(通过.gitignore)并使用post-checkout钩子进行复制/每次结账后将正确的文件链接到工作目录中。 前两个有优势,文件在回购站,但合并/纠正变得丑陋。

    第二个是有点壳攻击,每个检查回购的人都必须把钩子在他的.git / hooks目录中。此外,您可能需要针对Windows和Linux系统使用不同的脚本。



    详细阅读:
    Git条件文件


    We have a WordPress install that has a different config file for Live, Test, Dev. I understand how to get Git to ignore the wp-config.php file, but I want a different WP-config file in each of the branches. So that when a developer switches to Dev, it will use the database settings for Dev.

    My process, is:

    1. put live site into master.

    2. add .gitgnore

    3. commit

    4. create new Dev Branch

    Following this procedure, it means that I can no longer update the Dev branch with the Dev Config Details for other users to use.

    Can anyone advise on how to do this please?

    I understand, that you want to have different wp-config files in your branches, but they should not be merged, when you merge a branch into master.

    I can think of three solutions to your problem:

    1. You could put them into your branches and not merge them into master, but do cherry-picking instead.

    2. You could put them into your branches and commit the correct file after every merge.

    3. You could keep the files out of your repo completely (via .gitignore) and use the "post-checkout" hook to copy/link the correct file into the working-directory after every checkout.

    The first two have the advantage, that your files are in the repo, but merging/correcting gets ugly.

    The second is a bit of shell-hacking and everyone that has checked out the repo has to put the hook in his .git/hooks directory. Additionally, you probably need different scripts for windows and linux systems.

    Further reading: Git conditional files