【问题标题】:git shallow fetch not showing branches [duplicate]git shallow fetch 不显示分支[重复]
【发布时间】:2020-08-26 13:29:06
【问题描述】:

我之前用--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

【问题讨论】:

标签: git shallow-clone


【解决方案1】:

浅克隆中的默认 refspec 仅提及 refs/heads/master(而不是“常规”克隆中的 refs/heads/*),因此当您仅提及 branchname 时,git fetch 不知道应该更新哪个本地引用。


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

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

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

# at the end of your [remote "origin"] section :
fetch = refs/heads/branchname:refs/remotes/origin/branchname

【讨论】:

  • 这行得通。谢谢。奇怪的是,浅提取的行为不同。我还发现我需要做一个 git remote set-branches origin branchname 来设置远程跟踪
猜你喜欢
  • 2012-11-07
  • 2012-06-28
  • 2018-07-15
  • 2018-12-15
  • 2014-07-05
  • 2013-05-08
  • 1970-01-01
  • 2018-05-20
相关资源
最近更新 更多