Azure DevOps Server(2019,本地安装)中的分支列表正确显示所有部分中仅三个分支,因为所有其他分支已被 merge 和删除:
为什么git branch -r
返回大量旧的 merge 或删除的分支(通过 UI)?如何修复存储库以仅包含 Azure DevOps Server Web 界面中显示的分支?
最佳答案
当在源上删除分支时,跟踪该分支的本地分支不会被删除。这是一个明确的操作,因为那里可能还有您尚未推送的工作。要清理跟踪源上不再存在的分支的本地分支,您需要修剪远程分支。
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 togit fetch --prune <name>
, except that no new references will be fetched.
如果您想查看运行 prune 命令将删除的分支而不实际删除它们,请添加 --dry-run
选项。
示例:git remote prune origin --dry-run
编辑:
如torek commented :
You can also use
git fetch --prune
(abbreviatedgit fetch -p
) or setfetch.prune
totrue
.
The last one means you never have to rungit remote prune
orgit 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/