检出 git 存储库的一部分

cee*_*yoz 8 version-control git repository

我怎样才能检查出只是一个部分一个Git仓库的?我有一个包含多个模块的存储库,我只想在特定站点上安装其中一个模块。

在 Subversion 中,我会做svn export http://example.com/repository/path/to/module ./module-name.

Bre*_*ust 4

正如 @Chris 提到的,当前版本的 Git 确实支持稀疏签出。

要将本地存储库转换为仅包含指定目录:

cd <repo/location>
git config core.sparsecheckout true
echo desiredDir/ >> .git/info/sparse-checkout    # repeat to add multiple subdirs (the rest will be removed)
Run Code Online (Sandbox Code Playgroud)

现在,要删除除指定目录之外的所有目录:

 git read-tree -mu HEAD             # remove all, but those in .git/info/sparse-checkout
Run Code Online (Sandbox Code Playgroud)