gitsubmodules

gitsubmodules

Name

gitsubmodules - 在另一个仓库中安装一个仓库

概要

.gitmodules, $GIT_DIR/config

git submodule git <command> --recurse-submodules

描述

子模块是嵌入在另一个存储库内的存储库。子模块有其自己的历史; 它所嵌入的存储库称为超级项目。

在文件系统上,子模块通常(但并不总是 - 见下面的表格)由(i)位于$GIT_DIR/modules/其超级项目目录下的 Git 目录,(ii)超级项目工作目录内的工作目录以及.git根目录下的文件指向(i)的子模块工作目录。

假设子模块在$GIT_DIR/modules/foo/一个工作目录下有一个Git目录path/to/bar/,那么超级gitlink项目通过表单的树中的path/to/bar一个入口和其.gitmodules文件中的一个入口(请参阅gitmodules [5])来跟踪子模块submodule.foo.path = path/to/bar

gitlink条目包含超级项目期望子模块的工作目录所处的提交的对象名称。

所述部分submodule.foo.*.gitmodules的文件提供了额外的提示来GITS瓷层,诸如在哪里获得经由所述子模块submodule.foo.url的设置。

子模块可以用于至少两种不同的使用情况:

  • 使用另一个项目同时保持独立的历史 子模块允许您在自己的工作树中包含另一个项目的工作树,同时保持两个项目的历史分离。另外,由于子模块固定为任意版本,所以其他项目可以独立开发而不会影响超级项目,只有在需要时才允许超级项目项目自行修复新版本。

- Size of the git repository: In its current form Git scales up poorly for large repositories containing content that is not compressed by delta computation between trees. However you can also use submodules to e.g. hold large binary assets and these repositories are then shallowly cloned such that you do not have a large history locally.

- Transfer size: In its current form Git requires the whole working tree present. It does not allow partial trees to be transferred in fetch or clone.

- Access control: By restricting user access to submodules, this can be used to implement read/write policies for different users.

子模块的配置

子模块操作可以使用以下机制进行配置(从最高到最低优先级):

  • 支持获取子模块规格的那些命令的命令行。大多数命令都有一个布尔标志,--recurse-submodules是否递归到子模块中。例子是ls-filescheckout。一些命令使用枚举,比如fetchpush,您可以指定子模块如何受到影响。

形式

子模块可以采取以下形式:

  • 描述中描述的基本形式包含 Git 目录,工作目录,gitlink一个.gitmodules条目和一个条目。

第三方库的工作流程

# add a submodule git submodule add <url> <path>

# occasionally update the submodule to a new version: git -C <path> checkout <new version> git add <path> git commit -m "update submodule to new version"

# See the list of submodules in a superproject git submodule status

# See FORMS on removing submodules

人工拆分回购的工作流程

# Enable recursion for relevant commands, such that # regular commands recurse into submodules by default git config --global submodule.recurse true

# Unlike the other commands below clone still needs # its own recurse flag: git clone --recurse <URL> <directory> cd <directory>

# Get to know the code: git grep foo git ls-files

# Get new code git fetch git pull --rebase

# change worktree git checkout git reset

实施细节

克隆或拉取包含子模块的存储库时,默认情况下不会检出子模块; 您可以指示clone递归到子模块。该initupdate的子命令git submodule将保持子模块签出,并在您的工作树适当的修订。或者,您可以设置submodule.recursecheckout递归到子模块。