部分是作为练习,部分是因为它几乎有效,我觉得有必要完成它...
我可以git clone $repo --branch $ref --single-branch --depth 1
,它非常适合标签和头部。
只要$ sha为FULL值,我就可以git pull --depth 1 $repo $sha
且效果很好。但是:如果缩写,则失败,即使是1个字符也是如此。
有什么办法可以做到这一点?我正在尝试自动化git同步,并且很大的存储库是一个问题。使用深度1可以帮助很多,但我不知道如何使用缩写的SHA。
答案 0 :(得分:1)
我刚刚尝试使用git -c core.abbrev=40
选项,如“ Making git output full (un-abbreviated) hashes for all commands?”所示
git -c core.abbrev=40 --branch 05f7b9c710 --single-branch --depth 1 https://github.com/auser/arepo test
但这仍然失败:
Cloning into '`test`'...
warning: Could not find remote branch 05f7b9c710 to clone.
fatal: Remote branch 05f7b9c710 not found in upstream origin
如“ git clone --single-branch
does not work for sha / commit ids?”中所述
这是有意的,以便允许对可以从存储库中获取的内容进行一些控制,尤其是在单个对象数据库服务多个存储库的设置中。
顺便说一下,uploadpack.allowAnySHA1InWant
不是在GitHub端设置的 。
这意味着即使我要使用 full SHA1引用,它仍然会失败。
以您为例,如果您可以控制Git远程存储库托管服务器,则可以将设置设置为允许此类克隆。