Valter
Valter

Reputation: 2899

Ignore files when merging branches

When I merge branches I am trying to ignore web.config between each branch because each branch have different configuration in web.config.

Some reason, it is not working.
Am I missing something?

This is what i have so far.

.gitattributes

* text=auto
Web.config merge=ours

File Structure

 .gitignore
 .gitattributes
 project
 |____directory
 |____directory2
      |_____Web.config

I also set merge.ours.driver to true:

git config --global merge.ours.driver true

Upvotes: 1

Views: 892

Answers (2)

VonC
VonC

Reputation: 1323165

today I added a few new files and change some files but when i merge locally, this is not working.

A merge strategy like merge=ours only applies on specific files when they have conflicts. If you change a file only in one branch, then merge that branch, there is no conflict (ie, no concurrent modification).

In other words, merge=ours is not the right solution for your case (whether or not you are using Visual Studio 2015).

I would rather:

  • have a separate file per branch (web.config.master, web.config.mybranch, ...), in which you can modify each file as you want
  • declare a content filter driver (using a .gitattributes declaration) which would, on checkout automatically copy the right file as web.config.
    That web.config copied file would remain ignored and private.

smudge

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

branch=$(git rev-parse --symbolic --abbrev-ref HEAD)

Upvotes: 1

CodeWizard
CodeWizard

Reputation: 141946

You almost there, you missed something small - to mark the exact file that you wish to ignore. you have it with capital letters or if its right and nested it should be with **/web.config

echo 'web.config merge=ours' >> .gitattributes
echo '**/web.config merge=ours' >> .gitattributes

Do it and it will work.

Upvotes: 1

Related Questions