git - 为什么本地git显示的分支比服务器多

标签 git azure azure-devops

Azure DevOps Server(2019,本地安装)中的分支列表正确显示所有部分中仅三个分支,因为所有其他分支已被 merge 和删除:

current branches

为什么git branch -r返回大量旧的 merge 或删除的分支(通过 UI)?如何修复存储库以仅包含 Azure DevOps Server Web 界面中显示的分支?

local branches

最佳答案

当在源上删除分支时,跟踪该分支的本地分支不会被删除。这是一个明确的操作,因为那里可能还有您尚未推送的工作。要清理跟踪源上不再存在的分支的本地分支,您需要修剪远程分支。

git remote prune命令删除本地远程跟踪分支,该分支不再存在于远程上。

Prune
Deletes stale references associated with <name>. By default, stale remote-tracking branches under <name> are deleted, but depending on global configuration and the configuration of the remote we might even prune local tags that haven’t been pushed there. Equivalent to git fetch --prune <name>, except that no new references will be fetched.

来源:git documentation - prune

如果您想查看运行 prune 命令将删除的分支而不实际删除它们,请添加 --dry-run选项。

示例:git remote prune origin --dry-run

编辑:
torek commented :

You can also use git fetch --prune (abbreviated git fetch -p) or set fetch.prune to true.
The last one means you never have to run git remote prune or git fetch -p, at the cost of not being able to restore an accidentally-deleted server branch.

关于git - 为什么本地git显示的分支比服务器多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69098577/

相关文章:

git - 从 git 中删除但保留在工作目录中

ruby-on-rails - 初始推送大型 repo 的替代方法

c# - 未生成的 Azure Functions C# 输入绑定(bind)是 function.json

azure - 如何制作适用于 Office 365 的 Google Apps iDP

Azure Pipelines 自动重试任务

git - 我可以在 GitHub 上指定一个特定的分支 pull-only(只读)吗?

eclipse - Eclipse + EGit 入门——一头雾水

Azure Batch REST API,授权问题

c# - Azure DevOps 使用 API 获取工作项通知

azure - 在 Azure DevOps 上运行 DockerFile 构建命令时找不到项目依赖项