Git 存储库丢失了远程分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20338500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:24:38  来源:igfitidea点击:

Git repository lost its remote branches?

gitversion-control

提问by stochastic

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

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

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

Additional Information

附加信息

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

“git config --get remote.origin.fetch”为空(即该命令不产生任何输出)

"git remote show origin" shows

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

回答by torek

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

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



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

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

If git fetchis notrestoring them, then I wonder: what goes git config --get-all remote.origin.fetchprint? (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 fetch没有恢复它们,那么我想知道:什么云git config --get-all remote.origin.fetch打印?(这假设遥控器已命名origin;如果不是,则替换实际名称。)它应该设置为+refs/heads/*:refs/remotes/origin/*(再次假设名称origin)。特殊情况(例如获取笔记)可能会添加更多行。

回答by Xinlei Li

This solved my problem

这解决了我的问题

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

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

When I excute vi .git/config, I loose the fetch line:

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

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

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