仅克隆最新快照时的Swich分支

时间:2018-11-29 17:46:25

标签: git

由于存储库很大,我仅克隆了它的最新快照:

git clone --depth=1 <url>

此命令仅下载master分支的最新版本。因此,我获取了所需的分支:

git fetch --depth=1 origing testing

具有这样的输出:

remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 8 (delta 5), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.
From gitlab.com:lambda-hse/tatlin-hse/gotatlin
 * branch            testing    -> FETCH_HEAD

问题是当我这样做时(用于更改我所在的分支):

git checkout testing

什么也没有发生,并且回购仍在master分支上。在没有完全克隆存储库的情况下如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您可能会在输出中注意到,git提取了分支的sha1但未在本地创建引用,它只是在FETCH_HEAD中

* branch            testing    -> FETCH_HEAD

然后,如果您进行git log FETCH_HEAD,将会看到远处分支的头。

您可以通过指定完整路径来指定目的地和来源,从而在本地重新创建分支:

git fetch --depth=1 origin refs/heads/testing:refs/heads/testing

然后

git checkout testing