git prune
[pruːn]
用于清理仓库中不再被引用的对象。
● git prune --dry-run ✅查看哪些对象将被删除(不执行)
● git prune ✅清理所有 unreachable 对象
● git prune -v / -verbose ✅清理时输出详细信息(verbose output)
● git prune "2 weeks ago" ✅只清理两周前的 unreachable 对象
● git remote prune origin ✅远程仓库上dev1被删掉了,本地Git不会立刻知道这个变化,仍保留origin/dev1,此命令是删除origin/dev1
● git fetch --prune origin ✅fetch时自动清理
● git config --global fetch.prune true ✅配置默认行为
注意事项
存在 heads/1215
→ origin/1215
→ 托管平台/1215
1、删除托管平台/1215
, heads/1215
和 origin/1215
不会受到影响
2、再执行 git remote prune origin
会清除 origin/1215
,heads/1215
不会受到影响
参考
「引」https://git-scm.com/docs/git-prune
「引」https://git-scm.com/docs/git-remote
「引」https://git-scm.com/docs/git-fetch