git prune 实战指南:如何高效清理过期引用

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/1215origin/1215托管平台/1215
1、删除托管平台/1215heads/1215origin/1215 不会受到影响
2、再执行 git remote prune origin 会清除 origin/1215heads/1215不会受到影响


参考

「引」https://git-scm.com/docs/git-prune
「引」https://git-scm.com/docs/git-remote
「引」https://git-scm.com/docs/git-fetch

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值