1

What I Want
I working in windows and my project is asp.net mvc
I have two branches .Test and Master.
In both branches, i have config.cs
Each branch has its own config.cs with different data.
I want the config.cs files, Do not include in the merge.

my directory

-.git
-.vs
-MyProject
--config.cs
-.gitattributes.txt

my try
I found this link: git-scm.com
Who says to use the .gitattributes.txt

I write this line into .gitattributes.txt
config.cs merge=ours
and run this line:
git config --global merge.ours.driver true

But not work.
When I merge the Test branch into the Master branch, config.cs of Test, overrides on config.cs of Master.

Sasan Salem
  • 149
  • 1
  • 11

1 Answers1

0

Since you don't want to merge that file, it is better to not version it at all, but to generate it.

That generation would be through a content filter driver, using .gitattributes declaration.

Again:

  • you don't version config.cs at all (actually, remove it with git rm config.cs, followed by a commit)
  • version a template file config.cs.tpl, and two files with all possible values per environment (Test and master, so config.cs.test and config.cs.master).

smudge (image from "Customizing Git - Git Attributes", from "Pro Git book")

The generated actual file remains ignored (by the .gitignore): your actual working tree does not get "dirty".

The smudge script:

  • detect the right environment (like the branch, with branch=$(git rev-parse --symbolic --abbrev-ref HEAD))
  • selects the correct value file and generates the correct file based on the template the smudge script is applied on during a git checkout.

That way, you modify the config.cs.test value file as much as you want when developing: the config.cs file (not versioned) will be generated from those values.
But in master, a checkout of that same repo will trigger the generation of a master config.cs file, using the config.cs.master (versioned file) values.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250