Skip to content

Submodule

一句话解释

submodule 是仓库 embedded 内部 another 仓库 — 它 lets 你包含 foreign 仓库 as subdirectory 虽然 keeping 它 as 它的 own 仓库.

用大白话说

A Git submodule is a repository nested inside another repository. The parent repo stores a reference to a specific commit of the submodule, not the submodule's full history. This lets you include external projects (libraries, shared components) as subdirectories.

Submodules are useful for sharing code between projects without duplicating it. However, they are notoriously tricky to work with: cloning a repo with submodules requires --recursive, updating submodules requires specific commands, and team members must coordinate submodule versions.

Alternatives to submodules include package managers (npm, pip) for language-specific dependencies, or Git subtrees (which copy the content into the parent repo). Consider whether a submodule is truly necessary before using one.

示例

bash
# Add a submodule
git submodule add https://github.com/user/library.git lib

# Clone a repo with submodules
git clone --recursive https://github.com/user/project.git

# Update all submodules
git submodule update --remote

Submodules embed 仓库内部仓库. Use --recursive 当 cloning.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表