Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep different content of a particular file in a Git branch

I have a config.php which suppose to be different in content in different branches, e.g. testing and master.

I have asked in another question (Prevent merging a file from master with Git) that how to prevent this file from merging.

But I am wondering, is this the correct way to do so?

I believe this is quite a common use case to have different config files in different environments and you want the config to keep tracked, right?

like image 275
Ryan Avatar asked May 30 '12 04:05

Ryan


People also ask

What is git merge -- no FF?

In the event that you require a merge commit during a fast forward merge for record keeping purposes you can execute git merge with the --no-ff option. git merge --no-ff <branch> This command merges the specified branch into the current branch, but always generates a merge commit (even if it was a fast-forward merge).


1 Answers

For a config file, one solution is to not version it (that way, no merge issue!)

You would use a content filter driver:

content filter driver

You would version:

  • one value file (for master environment)
  • one value file (for dev environment)
  • one template file (with placeholder variables like @PORT_NUMBER@)
  • one 'smudge' script able, based on the current branch, and based on the content of the checked out file (here the template file) to generate the actual config file (which remains 'private', ie not-versioned).
  • one 'clean' script able to detect any value changes in the private config file, and store those changed values back in the (versioned) value files.
like image 76
VonC Avatar answered Oct 19 '22 22:10

VonC