0

我之前用 --depth 1 做了一个 git 浅克隆

之后,我想从远程获取一个深度为 10 的特定分支并结帐到该分支。

我能够从远程获取分支,但分支没有显示在git branch -a

更换个人信息后的日志如下

User@PC-NAME MINGW64 /d/Folder/application (master)
$ git fetch --depth 10 origin branchname
remote: Counting objects: 18624, done.
remote: Compressing objects: 100% (10327/10327), done.
remote: Total 18624 (delta 12993), reused 12045 (delta 7599)
Receiving objects: 100% (18624/18624), 530.73 MiB | 1.36 MiB/s, done.
Resolving deltas: 100% (12993/12993), completed with 3067 local objects.
From 10.100.x.x:Repository/application
 * branch                branchname -> FETCH_HEAD

User@PC-NAME MINGW64 /d/Folder/application (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
4

1 回答 1

1

浅层克隆中的默认 refspec 仅提及refs/heads/master(不像refs/heads/*“常规”克隆中那样),因此git fetch当您仅提及branchname.


对于一次性更新,请在命令行中提及明确的 refspec:

git fetch --depth 10 origin branchname:refs/remotes/origin/branchname

对于定期更新,请在您的 refspec 中添加.git/config

# at the end of your [remote "origin"] section :
fetch = refs/heads/branchname:refs/remotes/origin/branchname
于 2020-05-11T09:49:44.683 回答