How to handle various instances of index.php in codeigniter using git

I have a git repository that uses codeigniter as a framework. The main index.php differs from development to production because it sets an environment variable (either "production" or "development".

What is the best way to tell git to ignore changes in these two different environments? I do not necessarily want to add it to .gitignore, because it is a vital file. Is there a way to just suppress the changes?

0
source share
1 answer

You can just leave the file changed and never commit it, but it is very annoying. And there are sophisticated methods that use multiple branches and reloads. But it is also very dirty.

The easiest solution I have found is to use a grease filter in a working environment. See the git book for more details. You can use the smudge filter to replace a specific word with something else when placing an order.

In my setup, I use this filter (you can just add this to the .git / config file on your server):

[filter "htproduction"] smudge = sed 's/\\$site-mode\\$/$site-mode:production$/' clean = sed 's/\\$site-mode.*\\$/$site-mode$/' 

To activate this filter, add this line to .git / info / attributes (create this file if it does not exist):

 index.php filter=htproduction 

The effect of this is that all occurrences of $site-mode$ are replaced with $site-mode:production$ on your server. Now do something similar in the index.php file:

 if (strpos("$site-mode$", "production") !== false)){ do_only_on_server(); } 

It is highly recommended that you read smudge filters to understand what is happening and why Im not doing if ("$site-mode$" == "$site-mode:production$") (which didn't work).

Note. This answer assumes that you are using Linux on your server. This method also works with windows, but sed will probably not be available.

+2
source

All Articles