为什么我会看到已经被删除的远程分支? [英] Why do I see remote branches which were deleted already?

查看:129
本文介绍了为什么我会看到已经被删除的远程分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用命令 git branch -a 对于被删除的远程分支,我看到了几个 remotes / origin / branchname 已经从服务器。为什么会发生这种情况以及如何刷新列表?谢谢。

解决方案

这是由git设计的。

对于你使用的每个远程仓库的每个分支,git在 remotes /< remote name> / 下创建一个本地副本。这些被称为远程跟踪分支。



如果原始分支从远程存储库中删除,git不会自动删除您的本地远程跟踪分支。毕竟,你可能仍然需要它:也许你基于它的本地分支,或者你打算,或者你仍然需要它作为参考......



所以为了安全起见,git会保留分支。要摆脱它,你可以:


  • 使用 git branch -rd< remote name>直接删除它; /< branch name>

  • 运行 git remote prune origin (或使用 git fetch --prune )来删除远程中不再存在的所有远程跟踪分支



git branch -rd 的优点是它也可以脱机工作,而第二个选项需要访问远程。 / p>

Using the command git branch -a I see several remotes/origin/branchname for remote branches which were deleted from the server already. Why this happens and how to refresh the list? Thank you.

解决方案

This is by design in git.

For each branch of each remote repository you use, git creates a local copy under remotes/<remote name>/. These are called "remote-tracking branches".

If the original branch is deleted from the remote repository, git will not automatically delete your local remote-tracking branch. After all, you might still need it: Maybe you based a local branch on it, or maybe you intend to, or you still need it for reference...

So to be on the safe side, git will keep the branch. To get rid of it, you can either:

  • delete it directly using git branch -rd <remote name>/<branch name> or
  • run git remote prune origin (or use git fetch --prune) to delete all remote-tracking branches that no longer exist in the remote

The advantage of git branch -rd is that it also works off-line, while the second option needs access to the remote.

这篇关于为什么我会看到已经被删除的远程分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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