【问题标题】:Git repository lost its remote branches?Git 存储库丢失了它的远程分支?
【发布时间】:2023-03-18 23:55:01
【问题描述】:

我有一个 git 存储库,一个远程设置(“git fetch”有效),但它没有任何远程分支:“.git /refs/remotes" 文件夹不存在,并且

git branch -r 

什么都不返回(空列表,没有分支)。然而,实际的远程存储库确实有一个分支。如果我重新克隆远程仓库,我会得到另一个确实有远程分支的本地仓库。

我认为这种状态是不可能的。我的问题:

  1. 我到底是怎么进入这种状态的?
  2. 是否有可以运行的命令将“.git/refs/remotes”放回去? (缺少一个新的克隆,我已经完成了)。

其他信息

"git config --get remote.origin.fetch" 为空(即命令不产生输出)

“git remote show origin”显示

$ git remote show origin
* remote origin
  Fetch URL: <correct remote url here>
  Push  URL: <correct remote url here>
  HEAD branch: master
  Local ref configured for 'git push':
    master pushes to master (up to date)

【问题讨论】:

  • “git remote show origin”的输出是什么? [origin 是远程仓库名称]
  • 已编辑以包含“git remote show origin”的输出。除非我遗漏了什么,否则所有看起来都符合该命令。

标签: git version-control


【解决方案1】:

[编辑,2017 年 4 月] 如果您使用 --single-branch 制作原始克隆,您的 remote.origin.fetch 设置将成为问题。如果您使用了--depth 限制,那也意味着--single-branch。恢复正常的remote.origin.fetch 值如下所述,您将获得更完整的克隆。


通常,只需运行 git fetch 即可恢复您的远程跟踪分支。

如果git fetch 没有 恢复它们,那么我想知道:git config --get-all remote.origin.fetch 打印了什么? (这里假设遥控器名为origin;如果不是,则替换为实际名称。)它应该设置为+refs/heads/*:refs/remotes/origin/*(再次假设名称origin)。特殊情况(例如取笔记)可能会增加更多行。

【讨论】:

  • 不幸的是,git fetch 无法恢复它们。 “git config --get remote.origin.fetch”不产生输出
  • 手动将您指定的值放入此 repo 的 .git/config 文件下的 fetch 变量中确实会导致“git fetch”恢复丢失的远程分支。如果有人知道的话,让其他人知道这是如何发生的仍然很有价值。
  • 奇数。 git remote add 用一条fetch 线设置遥控器,要么是典型的,要么是镜像的特殊版本(--mirror=fetch)。克隆远程存储库以相同的方式设置origin 远程。是什么移除了它仍然是一个谜。
  • 也有这个问题 - 我想当我克隆这个 repo 时,我使用了--depth=15 可能是相关的?
【解决方案2】:

这解决了我的问题

git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*

当我执行 vi .git/config 时,我松开了获取线:

fetch = +refs/heads/*:refs/remotes/origin/*

【讨论】:

    猜你喜欢
    • 2014-06-20
    • 2013-02-21
    • 1970-01-01
    • 2014-11-27
    • 2022-11-09
    • 1970-01-01
    • 2011-03-03
    • 2011-01-09
    • 1970-01-01
    相关资源
    最近更新 更多