所以我想知道,既然git如此强大,是否有一种功能可以防止某些文件(是的,仅限文件:这是一个Magento项目,我们将开发的工具将位于自己的模块中,与应用程序的其余部分没有交集)合并到主分支中,但应该在其他分支中可用。
我们考虑使用git-flow,如果有帮助的话。因此,我们将拥有主分支,从中创建develop分支,从中创建所有功能分支。我们的想法是将此模块放在develop中,但永远不会合并回主分支。
我现在在思考,像忽略那些文件(.gitignore)只在主分支中这样的做法,这样行吗?
编辑1:项目结构
我觉得我需要更多关于项目结构的信息,它在这里:
+ main_folder/
+ magento/
|---+ app/
| |--+ code/
| | |--+ community/
| | |--+ core/
| | |--+ local/
| | |--+ Namespace1/
| | |--+ Module1/
| | |--+ Module2/
| | |--+ Namespace2/
| | |--+ Module1/
| | |--+ Module2/
| |--+ design/
| | |--+ frontend/
| | |--+ default/
| | |--+ default/
| | |--+ layout/
| | |--+ template/
| + js/
| + lib/
+ ezpublish/
开发工具模块必须包含在主项目中(仅限Magento部分)的不同位置,即app/code/local/Namespace1/Module3/、app/design/frontend/layout/dev.xml、app/design/frontend/template/dev/tool.phtml和js/dev/
编辑2:子模块选项
参考@VonC的答案,我已经做了以下工作:
- 在主分支中:
- git submodule add git@github.com:path/to/submodule.git devtool
- cd devtool
- git checkout 123abc #子模块的初始提交
- cd ..
- git add devtool
- git commit -m "添加子模块的初始提交"
- 在开发分支中:
- cd devtool
- git checkout abc213 #子模块的最后一次提交
- cd ..
- git add devtool
- git commit -m "子模块在最后一次提交时的状态"
- 回到主分支:
- touch .gitattributes
- 在 .gitattributes 中加入以下代码:
devtool merge=ours
- git add .gitattributes
- git commit -m ".gitattributes 指令"
但是在主分支中,子模块的内容是最后一次提交的内容。如果我切换到主分支的初始提交并返回开发分支,初始提交仍然存在(而我希望得到的是开发分支中的最后一次提交)。
所以显然我做错了什么,但是是什么呢?
.gitignore
的任何信息。当我尝试时,当我将一个分支合并到主分支时,主分支的.gitignore
也包括了该分支的内容。有关此事的任何信息吗? - OSdave