如何做git子模块以及为什么要使用git子模块 [英] How to do git sub modules and why to use git sub module
问题描述
git子模块的用途是什么?
如何创建git子模块?
它们如何与子树不同?
谢谢 Git Submodule
git仓库中的子模块就像是一个子目录,它本身就是一个单独的git仓库。这是一个很有用的功能,当你有一个项目在git中,这取决于其他项目的特定版本。
Git子树允许您将任何存储库作为另一个子目录插入。该子目录将成为超级项目的永久部分。
Git子树和子模块:
子树合并会永久性地将子树的内容和历史集成到合并的子树。
子模块只是对子模块中特定提交的引用。引用提交的更改历史记录保留在父模块中,但在父模块中没有跟踪子模块的内容或历史记录。
配置Git子模块:
-
您有一个项目 - 将其称为MyWebApp,它已经有一个github repo
-
你想在你的项目中使用jquery仓库
项目作为子模块。 -
子模块真的很容易引用和使用。假设您已将MyWebApp设置为回购站,请从终端发出以下命令:
-
cd MyWebApp
-
git submodule add git://github.com/jquery/jquery.git externals / jquery
这将创建一个名为 externals / jquery 的目录并将其链接到 github jquery存储库。现在我们只需要 init 子模块并将代码复制到它: -init --recursive
您现在应该拥有克隆到子模块中的所有最新代码。如果jquery repo发生变化,并且想要拉取最新的代码,只需再次发出submodule update命令即可。
请注意:
我的外部储存库通常有很多项目,因此我总是将repos归入外部目录。
b $ b -
You have a project -- call it MyWebApp that already has a github repo
You want to use the jquery repository in your project
You want to pull the jquery repo into your project as a submodule.
Submodules are really, really easy to reference and use. Assuming you already have MyWebApp set up as a repo, from terminal issue these commands:
cd MyWebApp
git submodule add git://github.com/jquery/jquery.git externals/jquery
This will create a directory named externals/jquery and link it to the github jquery repository. Now we just need to init the submodule and clone the code to it:git submodule update --init --recursive
You should now have all the latest code cloned into the submodule. If the jquery repo changes and you want to pull the latest code down, just issue the submodule update command again.Please note:
I typically have a number of external repositories in my projects, so I always group the repos under an externals directory.
I have found an github project and it uses git submodules.
What is the usage of git sub modules ?
How to create git sub modules ?
How they differ it from sub-tree ?
Thanks
Git Submodule:
A submodule in a git repository is like a sub-directory which is really a separate git repository in its own right. This is a useful feature when you have a project in git which depends on a particular versions of other projects
Git Subtree:
Git subtree allows you to insert any repository as a sub-directory of another one.the sub-directory would become permanent part of the super project
Git Subtree and submodule:
A subtree merge permanently integrates the contents and history of the subtree into the parent repository at the subtree of the merge.
A submodule is simply a reference to a specific commit in the submodule. A history of changes to referenced commit are kept in the parent module, but no contents or history of the submodule are tracked in the parent module.
Configure Git submodule:
这篇关于如何做git子模块以及为什么要使用git子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!