git: how do I merge between branches while keeping some changesets exclusive to one branch?

前端 未结 9 576
情书的邮戳
情书的邮戳 2020-12-24 15:38

There\'s a special place in hell for people who hardcode absolute paths and database credentials into multiple random places in web applications. Sadly, before they go to he

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 16:06

    A technical (Git) solution would be using git attributes, using the attribute merge.

    merge
    

    The attribute merge affects how three versions of a file is merged when a file-level merge is necessary during git merge.

    You will find in the SO question "How do I tell git to always select my local version for conflicted merges on a specific file?" an example of using such an attribute, to force keeping the local version of certain files when merging to a given branch.

    The problem with setting merge attributes is that the files that contain the paths may contain other changed code, which I want merged

    Do not forget you can associate any kind of script to manage those merges through git attributes. That include a script able to keep changes you want local, while merging the rest. It is more complicated to write such a "merge manager", but it is a way toward an ad-hoc automated solution.


    A less-technical solution would be to separate the configuration values from the configuration files:

    • the configuration file contains only names to be replaced
    • the configuration values are several files (one per environment) with the actual values for each name.

    A script is used to replace the name in the actual config file by the values of one of the config values files needed for a given environment.

提交回复
热议问题