Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent some commit/code to be merged into master

For the project I am working on, we decided to develop a tool to help the development, so this is something that should not be in production.
So I was wondering, as git is so awesome, if maybe there was a feature to prevent some files (yes, only files: this is a Magento project and the tool we are going to develop will be in his own module, no intersection with the rest of the application) to be merged into master, but should be available in other branches.
We are thinking in using git-flow, if that helps. So we would have master, from which we'll create develop, from which will create all our feature branches. The idea would be to have this module in develop but never merged back into master.

I am thinking now, something like ignoring those files (.gitignore) only in the master branch, would that work?

edit 1: project structure
I feel I have to give more info about the structure of the project, here it comes:

+ main_folder/
    + magento/
    |---+ app/
    |   |--+ code/
    |   |  |--+ community/
    |   |  |--+ core/
    |   |  |--+ local/
    |   |     |--+ Namespace1/
    |   |        |--+ Module1/
    |   |        |--+ Module2/
    |   |     |--+ Namespace2/
    |   |        |--+ Module1/
    |   |        |--+ Module2/
    |   |--+ design/
    |   |  |--+ frontend/
    |   |     |--+ default/
    |   |        |--+ default/
    |   |           |--+ layout/
    |   |           |--+ template/
    |   +  js/
    |   +  lib/
    +  ezpublish/

the development tool module will have to be included in the main project (only the magento part) in differents places, i.e. app/code/local/Namespace1/Module3/, app/design/frontend/layout/dev.xml, app/design/frontend/template/dev/tool.phtml and js/dev/

edit 2: submodule option
exploring @VonC's answer, here is what I've done:

  • in branch master:
    • git submodule add [email protected]:path/to/submodule.git devtool
    • cd devtool
    • git checkout 123abc #submodule's initial commit
    • cd ..
    • git add devtool
    • git commit -m "added submodule at initial commit"
  • in branch develop:
    • cd devtool
    • git checkout abc213 #submodule's last commit
    • cd ..
    • git add devtool
    • git commit -m "submodule at last commit"
  • back in branch master:
    • touch .gitattributes
    • in .gitattributes I've put this: devtool merge=ours
    • git add .gitattributes
    • git commit -m ".gitattributes directive"

but the submodule in master has the content of the last commit, and if I checkout the inital commit in master and checkout back to develop, the initial commit is still there (when I want the last commit in develop).
So I am obviously doing something wrong, but what?

like image 540
OSdave Avatar asked Dec 07 '22 05:12

OSdave


1 Answers

I would really recommend to use a submodule to isolate a set of files in its own repo.

The idea is: if you are using a submodule, all you need to do in your parent directory is to prevent the merge of one element (and only one): the special entry recording the SHA1 of said submodule.
You don't have to worry about the merge of the submodule files.

You can:

  • reference an empty submodule SHA1 in master
  • reference the last submodule commit in a 'devel' branch
  • prevent the merge of the submodule special entry between devel and master.
    (see for instance "Is it possible to exclude specific commits when doing a git merge?", with a .gitattributes directive.)
like image 174
VonC Avatar answered Dec 11 '22 11:12

VonC