Git fetch a specific commit by hash
Git fetch a specific commit by hash
回答1
As today I tried:
git fetch origin <commit-hash>
And it works like a charm! (git version 2.20.1)
Just be sure the <commit-hash>
is the full length reference
回答2
See "Pull a specific commit from a remote git repository":
With Git 2.5 (July 2015), you will be able to do:
git fetch --depth=1 <a/remote/repo.git> <full-lenght SHA1>
git cat-file commit $SHA1
If the SHA1 is "reachable" from one of the branch tips of the remote repo, then you can fetch it.
Caveats:
- you need a Git 2.5 remote repo server though, which will handle the
uploadpack.allowReachableSHA1InWant
config (and you need that config to be set totrue
, in order to allow a single commit fetch). - And, as illustrated in crgarridos's answer, you need the full SHA1, and you cannot use
git rev-parse
, since you don't have all the commits, as noted by Jim Hurne in the comments.
git config --global uploadpack.allowReachableSHA1InWant true
git fetch origin 4e16940d61d581daf7db90fd67e1e45a107c5139 这里到commit id必须是完整到,否则到话,不能正常识别。
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2021-08-10 哈啰单车流量问题
2019-08-10 .net reflector
2017-08-10 数据库中的Convert
2017-08-10 xml Data Type Methods in sql server
2015-08-10 VS中常用的快捷键
2015-08-10 wcf中的File-less Activation
2015-08-10 什么是SysWow64