How to do git sub modules and why to use git sub module

狂风中的少年 提交于 2020-01-24 03:12:27

问题


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


回答1:


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:

  • 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:

    1. cd MyWebApp

    2. 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:

    3. 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.



来源:https://stackoverflow.com/questions/31790481/how-to-do-git-sub-modules-and-why-to-use-git-sub-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!