Prevent file merge with master using Git

In another question, it is recommended to use .gitattributes to track the file, but not merge into another branch, but my use case below does not work ..

 mkdir git cd git git init echo "B" > b.txt git add b.txt git commit -m 'Initial commit' echo "b.txt merge=keepMine" > .gitattributes git add .gitattributes git config merge.keepMine.name "always keep mine during merge" git config merge.keepMine.driver "keepMine.sh %O %A %B" git commit -m 'Ignore b.txt' git checkout -b test # Create a branch git checkout master # Back to master and make change echo "Only in master" > b.txt git commit -a -m 'In master' git checkout test git merge master # The change in b.txt is being merged... 

Any idea? Thanks..

+4
source share
2 answers

I suspect this did not work because there were no merge conflicts.

However, I can confirm that git merge master --strategy=ours works as expected.

This may be what you are looking for: How to tell Git to always choose my local version

If you want to specify a specific merge strategy for a specific file, then you really need to write a special merge driver and indicate in the configuration of your repository that you want this merge driver to be used as the default value. See the link above on how to use it.

In short, the reason it doesn't work in your use case is because your use case is not a merge . It only displays a bunch of changes on the wizard with a temporary branch called a test, which is created and then moved up to manage later. In fact, you never enter a commit while in the test branch .

+1
source

The custom merge driver mentioned by carleeto is shown in the Tell git section not to combine binaries, but select ":

You can declare the type of merge you want in the .gitattributes file:

 echo yourConfigFile merge=keepMine > parentDirectory\.gitattributes 
0
source

All Articles