git-sparse-checkout

有时,一个项目依赖另一个项目的部分头文件。在构建CI时,只希望获得依赖的文件,不希望拉取全量仓库。此时,sparse-checkout可以派上用场。

示例脚本

#!/bin/bash
 
# This script sets up a sparse checkout for the projectV repository, focusing on specific directories.
# Run this exactly once right after you clone this repository.
 
REPO_URL=
if [ "$1" == "--http" ]; then
    # jenkins ci should use http protocol
    REPO_URL=http://github.com/abc/projectV.git
else
    REPO_URL=git@git.github.com:abc/prjectV.git
fi
 
git clone --filter=blob:none --no-checkout ${REPO_URL} -b release
cd projectV
git config core.sparseCheckout true
cat > .git/info/sparse-checkout <<EOF
src/base
src/api
src/api_impl/*.h
src/feeder_handler/utils.h
src/msg_codecs/*.h
src/common/*.h
EOF
git read-tree -mu HEAD