Here's the scenario
Master branch
-File name: xxx-master.txt
-File content:
code
code
ID=01
code
code
code
Dev branch
-File name: xxx-dev.txt
-File content:
code
code
ID=02
code
code
code
When merging master into dev, I'd like to keep xxx-dev.txt as the file name and ID=02, but everything else from master. And vice versa when merging dev into master. Is that something I can make GIT understand?
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:
xxx-dev.tpl
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With