【问题标题】:'git branch -a' shows upstream repository that no longer exists'git branch -a' 显示不再存在的上游存储库
【发布时间】:2019-11-15 09:49:15
【问题描述】:

git branch -a 显示

master
remotes/origin/master
remotes/upstream/bugfix/corrupted-deb
... (many more remotes/upstream branches)

存储库upstream 不再存在。如何永久删除僵尸分支remotes/upstream/bugfix/corrupted-deb等?

文件.git/config包含不超过

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@<myurl>
    fetch = +refs/heads/*:refs/remotes/origin/*

任何对upstream 的有意引用早已不复存在。

命令git remote prune origin [https://stackoverflow.com/questions/8766525] 不影响upstream。明显的变体git remote prune upstream 导致fatal: 'upstream' does not appear to be a git repository ...

【问题讨论】:

  • git remote -v 是否显示 upstream
  • 不,它只显示两行(获取/拉取)引用origin

标签: git


【解决方案1】:

试试:

git update-ref -d refs/remotes/upstream/bugfix/corrupted-deb

有时你可能有一个象征性的参考:

remotes/origin/HEAD -> origin/master

要删除remotes/origin/HEAD,运行:

git symbolic-ref -d refs/remotes/origin/HEAD

要删除所有remotes/upstream,请尝试:

git for-each-ref refs/remotes/upstream --format="%(refname)" | while read ref;do
    git update-ref -d ${ref}
done

【讨论】:

  • 是的,git update-ref -d refs/remotes/.... 有效。但实际上,我有大量死去的上游分支(我编辑了我的问题来这么说)。有什么方法可以一次性全部删除?
【解决方案2】:

git branches -a 只是告诉您在您的.git 文件夹中本地有一个文件(有时通过git fetch 创建)。只需将其删除:

.git/refs/remotes/upstream/bugfix/corrupted-deb

为了举例说明,我创建了一个小型测试项目并手动创建了一个文件 .git/refs/remotes/test/feature/mybranch 指向我所做的单个提交的 sha。

运行 git branch -a 现在产生:

/c/dev/remotetest (master)
$ git branch -a
* master
  remotes/test/feature/mybranch

删除文件.git/refs/remotes/test/feature/mybranch 后运行git branch -a 现在产生:

/c/dev/remotetest (master)
$ git branch -a
* master

/马丁

【讨论】:

    猜你喜欢
    • 2012-02-04
    • 1970-01-01
    • 2015-12-30
    • 2020-08-18
    • 1970-01-01
    • 2013-01-29
    • 2018-05-03
    • 1970-01-01
    • 2019-09-14
    相关资源
    最近更新 更多