【问题标题】:stale remote branches are not cleaned from upstream references不从上游引用中清除陈旧的远程分支
【发布时间】:2015-12-08 09:57:36
【问题描述】:

在 git repo 中调用 meld 时,我在 meld 打开之前收到一堆警告:

# from within a git repo :
$ meld .
fatal: bad revision '^origin/branch/one'
fatal: bad revision '^origin/branch/two'
fatal: bad revision '^origin/branch/three'
...

这只是打印在STDERR 上的警告,meld 之后运行良好并显示预期的差异。

这些分支中的大多数都有本地结帐,但在 origin 上没有匹配的远程引用。
其中一个引用甚至在本地都不存在(它与现有分支只有一个拼写错误)。

有人知道我可以处理这些可耻的消息吗?

【问题讨论】:

    标签: git meld


    【解决方案1】:

    问题出在我的 repo 配置中。

    一些本地分支仍在跟踪陈旧的远程分支:
    .git/config 文件仍然包含部分:

    [branch "branch/one"]
        remote = origin
        merge = refs/heads/branch/one
    

    即使远程分支 branch/one 不再存在,并且我的本地引用 origin/branch/one 已(正确)删除。

    我没有找到任何直接命令来清理我的本地分支。
    我希望git remote prune origin 能解决这个问题,但它没有。

    这是我发现让我的本地分支停止跟踪陈旧的远程分支的一种方法:

    # enumerate all local branches, and print "branchname upstreamname" :
    git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads |\
    
    # keep branches which track a remotre branch in origin :
    grep "origin/" |\
    
    # loop on output :
    while read local remote; do
      # use any command which fails on an invalid ref :
      git show $remote -- > /dev/null
      # if it failed : stop tracking this stale remote
      if [ $? != 0 ]; then
        git branch $local --unset-upstream
      fi
    done
    

    【讨论】:

      猜你喜欢
      • 2021-08-01
      • 2021-06-21
      • 2011-03-12
      • 2013-07-02
      • 2016-12-28
      • 2018-11-19
      • 2022-08-13
      • 2012-07-19
      • 2015-05-20
      相关资源
      最近更新 更多