我对 Git 还很陌生:我来自 SVN,在那里我发现了非常强大的 :external 功能。在 Git 中我没有找到类似的东西:
-
子模块非常适合添加并不总是需要的项目模块。它们必须在存储库克隆后初始化,并且不能仅包含原始项目的子目录。
-
subtrees对于添加库确实很有用(它们还允许包含子目录),但是推动它们确实很痛苦。
所以场景是这样的:我有一个项目,我想在其中包含一些库。我希望能够更改所有这些库并将它们推送到自己的存储库中。此外,其中一些库是较大项目的子目录(例如,如果项目还包含演示或自述文件,我不会在我的项目中包含这些目录)。
我怎样才能做到这一点?
我试过了:
-
http://progit.org/book/ch6-7.html http://progit.org/book/ch6-7.html + http://posterous.timocracy.com/git-sub-tree-merging-back-to-the-subtree-for http://posterous.timocracy.com/git-sub-tree-merging-back-to-the-subtree-for(不允许仅合并子目录,否则我无法看到它);
-
http://www.tipstank.com/2011/02/21/git-subtree-notes-and-workflows/ http://www.tipstank.com/2011/02/21/git-subtree-notes-and-workflows/(同上,不处理子目录包含);
-
http://psionides.eu/2010/02/04/sharing-code- Between-projects-with-git-subtree/ http://psionides.eu/2010/02/04/sharing-code-between-projects-with-git-subtree/(看不到任何关于推送的内容);
-
http://h2ik.co/2011/03/having-fun-with-git-subtree/ http://h2ik.co/2011/03/having-fun-with-git-subtree/(看不到任何有关推送的信息)
好吧,如果你已经达到了这一点,感谢你的耐心,现在我想尝试一些其他的东西,因为现在我的结论是:“Git 中不允许子树推送”ç_ç
评论中的几点评论:
- git 子模块与 svn external 不同 https://stackoverflow.com/questions/3131912/why-are-git-submodules-incompatible-with-svn-externals/3132221#3132221
- 对子模块所做的任何修改可以推送到自己的远程仓库 https://stackoverflow.com/questions/1979167/git-submodule-update/1979194#1979194.
- "规划 git 迁移的存储库布局 https://stackoverflow.com/questions/9394286/planning-repository-layout-for-git-migration/9395375#9395375” 说明您不能总是直接使用子模块,因为目录结构并不完全符合您的需要。
所以我建议:
- 加载(git checkout)父存储库及其所有子模块
- 在其他地方创建正确的结构,并使用到子模块(或子模块的子目录)的符号链接来实现您所需要的。
- 定期返回父存储库中的 git,以检测任何更改(从 Git 外部创建的其他目录结构完成),以便提交并推送所有子模块修改,然后提交并推送父存储库。
git 结帐
parent repo
+
+--> main project
+
+-> mainDir1
+-> mainDir2
+--> lib1
+
+-> lib1Dir1
+-> lib1Dir2
+--> lib2
+
+-> lib2Dir1
+-> lib2Dir2
以及你自己的项目目录结构(例如)
+--> main project (symlink to ../parent/main project)
+
+-> mainDir1
+-> mainDir2
+-> lib1Dir1 (symlink to ../parent/lib1/lib1Dir1)
+-> lib1Dir2 (symlink to ../parent/lib1/lib1Dir2)
+-> lib2Dir2 (symlink to ../parent/lib1/lib2Dir2)
(注意没有lib2Dir1
(例如)因为在你的实际项目中你不需要它)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)