How to make Git preserve specific files while merging
Christophe Porteneuve
16311

I have tried this and it does not work (I have checked on Windows PC as well as on Linux server). Every time it overrides master branch’s file. I had created .gitattributes file (config.php merge=ours) in my repository’s root directory (where .git directory resides) and I have also executed “git config — global merge.ours.driver true” command on command prompt. But nothing worked.

Find my flow:

master branch:

  1. config.php (text is “master config file”)
  2. index.html (text is “master index file”)

Both files were committed

stage branch:

  1. config.php (text is “stage config file”)
  2. index.html (text is “stage index file”)

Merge command:

git checkout master

git merge stage

and boomed. It overridden master branch’s config.php with stage branch’s config.php. So now master branch’s config.php says “stage config file”.