获取仓库中指定文件,而不用下载整个仓库。
- 首先你需要了解Sparse checkout
"Sparse checkout" allows to sparsely populate working directory. It uses skip-worktree bit (see git-update-index(1)) to tell Git whether a file on working directory is worth looking at.
命令
#初始化
git init
#启用Sparse Checkout
git config core.sparseCheckout true
#在sparse-checkout文件中指定文件目录信息(需要拉取的目录);多个文件,多次写入即可
echo 'github file directory' >> .git/info/sparse-checkout
#查看.git/info/sparse-checkout文件
vi .git/info/sparse-checkout
#添加远程仓库
git remote add -f origin https://github.com/****.git
#拉取
git pull origin master
当前工作目录下只会有下载指定的目录;这种方法对于获取大的项目部分信息是极为方便的。
网友评论