git 不用clone整个远程仓库,只把特定的commit给fetch下来的方案
Git 远程 方案 仓库 不用 特定 commit 整个
2023-09-11 14:19:35 时间
一个麻烦点就是,我需要阅读一个大点的开源项目,远程仓库的代码量太庞大了,如果我需要git reset --hard [commit sha1]感兴趣的commit快照,就首先得git clone整个远程仓库,
时间需要等待太长,而且网络一旦有问题还会功亏一篑。所有有没有一种只拉取远程仓库中的某个commit呢?有。命令行如下:
# make a new blank repository in the current directory
git init
# add a remote
git remote add [nick_name] [url://to/source/repository]
# fetch a commit (or branch or tag) of interest
# Note: the full history of this commit will be retrieved
git fetch [nick_name] <sha1-of-commit-of-interest>
# reset this repository's master branch to the commit of interest
git reset --hard FETCH_HEAD
references:
https://stackoverflow.com/questions/14872486/retrieve-specific-commit-from-a-remote-git-repository
https://stackoverflow.com/questions/14370157/git-fetch-a-specific-commit-by-hash
https://stackoverflow.com/questions/3489173/how-to-clone-git-repository-with-specific-revision-changeset#
相关文章
- [Git] git shortlog 找出最懒的程序员
- [Git] git revert ( revert commit 和 revert merge)
- Git忽略文件
- 【问题解决方案】git/github本地和远程仓库的重命名
- Git远程02:git clone都做了什么
- Git远程01:git remote相关操作
- git使用简单指南
- [Git] Change the commit message of my last commit
- [Practical Git] Compare file changes with git diff
- Git@OSC代码托管(含Git教程!important非命令行)
- Git撤回已经推送(push)至远程仓库提交(commit)的版本
- 【转载】如何解决failed to push some refs to git
- Git设置代理和取消代理的方式
- 每日一条 git 命令行:git clone https://xxxxx.git -b 12.0 --depth 1
- Git知识总览(二) git常用命令概览
- git 生成秘钥
- git 切换远程仓库push
- 【Git总结大全】git操作从入门到实战(总结篇)
- 【Git技巧】第十一篇 更新远程分支列表
- google colab中使用git clone导入代码至google drive
- git只提交部分修改的文件(提交指定文件)
- C/C++开发,关闭vscode中的插件git工具