Git仓库丢失了它的远程分支? [英] Git repository lost its remote branches?

查看:575
本文介绍了Git仓库丢失了它的远程分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个远程设置(git fetch工作)的 git仓库,但它不具有任何远程分支:.git / refs / remotes文件夹不存在,并且

  git分支-r 

不会返回任何内容(空列表,不分支)。然而实际的远程仓库确实有一个分支。如果我重新克隆远程回购,我会得到另一个 具有远程分支的本地回购。



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


  1. 我究竟是如何进入这种状态的?

  2. 是否有可以运行的命令将.git / refs / remotes放回去? (缺少一个新的克隆,我已经完成了)。

其他信息

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

显示

  $ git远程显示原点
*远程原点
提取网址:<此处的正确远程网址>
推送网址:<此处的正确远程网址>
HEAD分支:master
为'git push'配置的本地ref:
主人推送到master(最新)


解决方案

如果您使用创建了原始克隆 - 单分支,你的 remote.origin.fetch 设置将会成为问题。如果您使用 - 深度限制,那也意味着 - 单个分支。恢复下面描述的正常的 remote.origin.fetch 值,您将得到更完整的克隆。






通常,只要运行 git fetch 就可以恢复您的远程追踪分支。



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


I have a git repository that has a remote set up ("git fetch" works), but it doesn't have any remote branches: the ".git/refs/remotes" folder doesn't exist, and

git branch -r 

returns nothing (empty list, no branches). Yet the actual remote repository does have a branch. If I re-clone the remote repo, I get another local repo that does have remote branches.

I didn't think this state was possible. My questions:

  1. How on earth did I get into this state?
  2. Is there a command that can be run to put ".git/refs/remotes" back? (short of a fresh clone, which I've done already).

Additional Information

"git config --get remote.origin.fetch" is blank (i.e. the command produces no output)

"git remote show origin" shows

$ 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)

解决方案

[Edit, April 2017] If you made your original clone with --single-branch, your remote.origin.fetch setting will be the problem. If you used a --depth limit, that too implies --single-branch. Restore the normal remote.origin.fetch value described below and you will get a fuller clone.


Normally, just running git fetch should restore your remote-tracking branches.

If git fetch is not restoring them, then I wonder: what goes git config --get-all remote.origin.fetch print? (This assumes the remote is named origin; if not, substitute the actual name.) It should be set to +refs/heads/*:refs/remotes/origin/* (again assuming the name origin). Special cases (such as fetching notes) might add more lines.

这篇关于Git仓库丢失了它的远程分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆