git gc
git
用法
git gc [--aggressive] [--prune=<date>]把零散对象打包、丢掉无人引用的,从而缩小 .git;--prune=now 连 reflog 还拉着的提交一起丢掉,撤销 reset 的安全网也就没了。
常用选项
| 选项 | 含义 |
|---|---|
| --aggressive | repack harder; slow, occasionally worth it |
| --prune=<date> | drop unreachable objects older than that |
| --prune=now | drop them all, which also throws away reflog-only commits |
| --auto | do nothing unless there is enough loose junk |
| --no-prune | repack but keep unreachable objects |
| -q | no progress output |
示例
git gcpacks loose objects and shrinks .git
git gc --autothe cheap check git itself runs after some commands
git gc --prune=now --aggressivesmallest result, and no way back to lost commits
难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. git gc 是做什么的?
把零散对象打包、丢掉无人引用的,从而缩小 .git;--prune=now 连 reflog 还拉着的提交一起丢掉,撤销 reset 的安全网也就没了。
Q. 怎么写?
git gc [--aggressive] [--prune=<date>] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 6 个,完整列表在 man git。这条命令属于git。
相关命令
man 手册: man git-gc