不会从上游引用清除过时的远程分支

时间:2015-12-08 09:57:37

标签: git meld

在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上没有匹配的远程引用 其中一个引用甚至不存在于本地(它是远离现有分支的一个拼错)。

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

1 个答案:

答案 0 :(得分:1)

问题出在我的回购配置中。

一些当地分支机构仍在跟踪过时的远程分支:
.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
相关问题