1

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
Community
  • 1
  • 1
Valter
  • 2,859
  • 5
  • 30
  • 51

2 Answers2

1

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.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • It worked fine yesterday, today i added a few new files and change some files but when i merge locally, this is not working. Any suggestions? – Valter Jan 30 '17 at 20:32
  • I am using Visual Studio 2015 and Diff & Merge Tools Git Setting is set to Visual Studio. Do you think this is the issue. – Valter Jan 30 '17 at 20:34
1

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)
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This is new for me, where do i add the smudge and what do i place in the smudge. Can you provide me an example? – Valter Mar 21 '17 at 13:26
  • @Valter See http://stackoverflow.com/a/2316728/6309 (and http://stackoverflow.com/questions/2316677/can-git-automatically-switch-between-spaces-and-tabs/2318063#2318063) the smudge script needs to be in your $PATH. But anyway, you did chose the other answer. – VonC Mar 21 '17 at 13:30