10

I'm working on a (Django) website with two branches: master and dev.

master is the production version and no work should be done here directly. All the changes should come from merging dev branch, once it is considered to be stable.

dev, as you may guess, is the development branch and all the changes are made here (and subbranches).

In the server I have two websites working, the production one (uses master branch) and another private for development, with dev subdomain that uses dev branch.

The problem is that all the configuration files, static files (images, etc.) are inside the control version to be able to easily push them to the server. But, if these kind of files (static, config...) are modified in dev to just debug in the server and then I need to merge with master... How can I set some files and dirs to be ignored when merging dev into master?

I've been searching and I've found some related questions, but they tell you to use .gitattributes with merge=ours. However, this approach has a big caveat: it only applies the strategy if the file is modified in the two branches, but this isn't my case.

Any tips on how should I go on?

Community
  • 1
  • 1
Caumons
  • 9,341
  • 14
  • 68
  • 82
  • @givanse have you realised that this question already has an accepted answer and that the question marked as possible duplication was already referenced from this question? – Caumons Feb 13 '14 at 19:42
  • I was reading multiple similar questions, must have mixed them at some point. I deleted the flag, please consider using the actual title of the linked source. – givanse Feb 14 '14 at 00:21

3 Answers3

7

git checkout master

git merge --no-log --no-ff --no-commit dev

git checkout master &ltfiles-you-don't-want-to-merge&gt


git add &ltfiles-you-don't-want-to-merge&gt

git commit -a

~~~ Test / Build ~~~

git push origin master 


forvaidya
  • 3,041
  • 3
  • 26
  • 33
  • #1 - Do a merge but don't commit; then checkout *those* Files off master branch, thereby ignore merge result and add them to index. Rest continue with regular merge cycle, conflict resolution, builds and commits. – forvaidya Sep 28 '13 at 16:45
  • I realised this, but I don't get why you first checkout and then add the same files :S Would it be enough if I checkout the files I don't want to commit, whithout adding them back again? – Caumons Sep 28 '13 at 16:47
  • staging checked out files (git add) is (un)necessary as files are same as master branch; but I like to stage them. Think you have follow a procedure what you use for merge conflict resolution – forvaidya Sep 28 '13 at 16:52
  • Ok! And one more thing... the fags `--no-log` and `--no--ff` are really necessary when doing the merge? Or just setting `--no-commit` would be enough? – Caumons Sep 28 '13 at 16:56
  • 3
    Please include some explanations to your answer text – Dmitry Pashkevich Sep 28 '13 at 16:57
  • --no-ff - Means regardless of FF or NOT create merge commit. This flag is essential. --no-log - Do not inherit log messages. – forvaidya Sep 28 '13 at 17:00
  • OK, I understand `--no-ff`. But I don't get the benefit from `--no-log`. What's the purpose of not inheriting log messages? Will I have any troube if I forget to use it, as per `--no-ff`? – Caumons Sep 28 '13 at 17:06
3

To be honest, git sounds like the wrong place to be solving this problem.

Django offers facilities for having separate settings/configuration for production and development environments. I suggest you take a look at this post: Django: How to manage development and production settings?

If you follow the advice in the post above, you can muck with the configuration, etc. for your dev environment and then merging to master will be harmless as production will have its own configuration.

Community
  • 1
  • 1
ksimons
  • 3,797
  • 17
  • 17
  • You are right; I have answered this more as git problem rather than web best practice. – forvaidya Sep 28 '13 at 17:06
  • This only talks about settings, but I'm looking for more... What about the contents inside `media` and `static` dirs? – Caumons Sep 28 '13 at 17:14
  • Use different directories for production and development environments if you need to: https://docs.djangoproject.com/en/dev/howto/static-files/ – ksimons Sep 28 '13 at 17:28
  • Regarding settings... I use a module called `settings_shared.py` that contains all common settings. Then, I have a `settings.py` file that imports all variables from `settings_shared`. Each branch defines its own `settings.py`. Regarding static files... I don't want to be able to modify static contents from the other branch having `static_master` and `static_dev`. Doing "manual merges" I think that is a good solution for my case. Anyway, thanks for your comments, the've been useful! :) – Caumons Sep 30 '13 at 01:50
-1

It's been a long time. But I'm searching for a same solution. Out of nowhere, it just pops in my head: use a sub module for configurations. With a sub module, you can have multiple branches for different configurations.

Use symbolic links to link files from the sub module (in a sub directory).