git clone 大项目

如果使用git作为source管理工具的话,我们往往会遇到随着项目的进展git仓库越来越大,要想clone一个项目需要很长的时间.下面介绍自己在工作中用到的几种优化方式

浅clone

git clone --branch develop --depth=1 [email protected]:xx.git

上面的命令中使用了branch和depth

depth

depth参数可以让git只clone指定数量的commit记录,从而缩短clone的时间

官方文档:

Create a shallow clone with a history truncated to the specified
number of commits. Implies --single-branch unless --no-single-branch
is given to fetch the histories near the tips of all branches. If you
want to clone submodules shallowly, also pass --shallow-submodules.

branch

当远端有多个分支的时候,使用branch来指定clone哪一个分支,否则将会clone仓库中的HEAD

官方文档:

Instead of pointing the newly created HEAD to the branch pointed to
by the cloned repository’s HEAD, point to <name> branch instead. In a
non-bare repository, this is the branch that will be checked out.
--branch can also take tags and detaches the HEAD at that commit in
the resulting repository.

clone指定目录

git clone -b develop --filter=blob:none --depth=1  --sparse  [email protected]:xx.git
cd xx
git sparse-checkout set dir
  1. 上面先使用了filter和sparse参数clone下一个空的目录
  2. 然后再通过sparse-checkout checkout指定的目录

猜你喜欢

转载自blog.csdn.net/scdnshijiemengxiang/article/details/126165089