jskidd3
jskidd3

Reputation: 4783

Git deleting files in merge

I am new to git and am trying to perform a simple merge but can't seem to get it working.

I have a web code base that is reused across about 5 clients. Most of this code is the same, however there is for example a few config files and an uploads folder which is unique to each client.

So, I set out to try and create a solution that allows me to package up each site without having to manually upload the custom files each time.

Here is what I do:

git checkout master
git checkout -b site1

Deletes all files except config files and uploads folder

git commit -a -m "Removed duplicates, remaining files are unique/custom"
git checkout master
git checkout -b temp
git merge site1

It's at this point that I get stuck. The merge just deletes all of the files except the custom ones, where what I want it to do is simply merge in the custom files and leave the master files that were copied in from checkout alone.

Can anyone please tell me how to stop this from happening?

Upvotes: 0

Views: 299

Answers (2)

Derek
Derek

Reputation: 1816

For deployment-specific files you have 2 solutions :

1 - Don't put the config file on Git (preferred)

Instead of the config file, put a dist file with a sample config on git. For example, if your config file name is config.ini, then put a config.ini.dist on Git containing the same structure as the config file but with fake values (you don't want your server credentials to be on your versionning system). Then when you deploy to your servers, copy the dist file to the real name of your config file and edit it with the proper values.

2 - Create a branch for each environment

I think that's what you were trying to do here. Create a branch from master and edit your config files in this branch with the appropriate values for the config file. Don't touch any other file (and don't delete them!!). You won't ever merge these branches back to master. Continue working on bugfixes and features on the other branches and merge to master.

When you are done coding and ready to deploy, merge the master branch to each of the env-specific branches. Update your code on each server by checking out the proper branch. This means that you will have a lot of merging to do on each deployment, and that you will store your database credentials on your versionning system (baaaad). Go for the first solution.

Upvotes: 1

Tim
Tim

Reputation: 43354

Because you did git commit -a -m "Removed duplicates, remaining files are unique/custom", only the custom files are left in that branch.

Of course, when you merge with that, it removes everything except for the custom files.

Git merge does not combine files together in a branch, it combines commits. Therefore because you merge with the commit that "Removed duplicates, remaining files are unique/custom", the merge does exactly that, too.

I think you're going to have to manually copy the custom files to the new branch. Unless you have a commit somewhere that only adds the custom files, in that case you could cherry-pick that commit in the new branch.

Upvotes: 1

Related Questions