GIT merge -keep specific parts of one branch and everything else of the other

前端 未结 1 1569
清歌不尽
清歌不尽 2020-12-11 06:26

Here\'s the scenario

Master branch

-File name: xxx-master.txt

-File content:

code code ID=01 code code code

Dev branch

相关标签:
1条回答
  • 2020-12-11 06:47

    This is typically a case where you need to keep (for a given file, here xxx-dev.txt) different content based on branches, one way is to:

    • version only a template file xxx-dev.tpl
    • version value files named after the branches: xxx-dev.dev, xxx-dev.master: since they are different, there is no merge issue.

    For that, you would register (in a .gitattributes declaration) in your submodule repo a content filter driver.

    (image from "Customizing Git - Git Attributes", from "Pro Git book")

    The smudge script, associate to the template file (*-dev.txt), would generate (automatically on git checkout) the actual xxx-dev.txt file by looking values in the right xxx-dev.<branch> value file. The generated actual xxx-dev.txt file remains ignored (by the .gitignore).

    See a complete example at "git smudge/clean filter between branches".

    Your smudge script can determine the name of the checked out branch with:

    branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
    
    0 讨论(0)
提交回复
热议问题