git忽略历史,仅拉取最新代码

原因

项目内容过大,且提交次数太多时,如果整个进行git clone下载时间会很长

解决方案

仅拉取最新的版本

git clone –depth=1 url

–depth可用于指定拉取最近的几次提交

存在的问题

–depth 拉取的只是默认分支,如果拉取其他分支可以使用如下命令:

1
2
3
$ git remote set-branches origin 'remote_branch_name'
$ git fetch --depth 1 origin remote_branch_name
$ git checkout remote_branch_name