有解决办法么?—— 有一些:如果只是 git add
,没有 git commit
,可以用 gc 回收。
git fsck --unreachable
可以查看哪些 object 已经不在使用:
$ git fsck --unreachable
notice: HEAD points to an unborn branch (master)
Checking object directories: 100% (256/256), done.
Checking objects: 100% (1/1), done.
notice: No default references
dangling blob e27718b554b78f3a85c36ddf4a60e596bac4e726
dangling blob 23c6ba2171700d3f29cf10eb748b8485263518d3
dangling blob 24a51e4d7effea055a9c949aee3feeab795737f5
dangling blob 6583cb0c98b5fe2a7a10becd38a3ddcf7961a7de
dangling blob 262efee938d25e2cf399fb833df602e9fdb54415
dangling blob a500f663ec03bebd3e0bd897b6b50658702f961d
dangling blob eb93897857e950466e55e70d98f488788a1af8fc
dangling blob f9c1d647aa1c5797a144e846d42b3fbe9258ebfe
dangling blob 9b796fd8bfc3d6d061149b971f888b81a1cf6c99
dangling blob 9caf8eacc33bab850f15bfd14d22faa227f9d050
dangling blob bb0fa0eae291e6bc1a6f36f286b78f0fba6b969b
dangling blob febd81b4d4de079f0148095c904a569951327f7c
git gc --prune=now
可以立即回收,即删除无用的 object。
$ git gc --prune=now
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), done.
Total 1 (delta 0), reused 1 (delta 0)
$ du -sh .git/objects/
28K .git/objects/
如果已经 git commit
了,可以进行“提交压缩”,方法多种:
git rebase -i
逐个需要想压缩的提交为 s 状态;git merge --squash
合并到另一个分支的时候压缩,然后删除本分支