User Tools

Site Tools


git_gc

This is an old revision of the document!


Table of Contents

Overview

How to clean up dangling and unreachable objects.

Links:

SYNOPSIS

git gc
  [--aggressive]
  [--auto]
  [--quiet]
  [--prune=<date> | --no-prune]
  [--force]
  [--keep-largest-pack]

OPTIONS

In part:

--prune=<date>
    Prune loose objects older than date (default is 2 weeks
    ago, overridable by the config variable gc.pruneExpire).
    --prune=all prunes loose objects regardless of their age
    and increases the risk of corruption if another process is
    writing to the repository concurrently; see "NOTES" below.
    --prune is on by default.

--no-prune
    Do not prune any loose objects.

Examples

Current situation:

$ git fsck
Checking object directories: 100% (256/256), done.
Checking objects: 100% (11352/11352), done.
dangling blob 4e811469e1f97f114ed2d3e42fdcec1aedbad174
dangling blob 2384122beb433045ec091b5131d294b55fe7fb43
dangling blob db93da5493a753c01d87d665beb748ac255c8547
dangling blob af96a0d3d093de55ddcad81ed92773a179465d9f
dangling commit 659d5f247d9b3d4005d9e074f960e473bb0cf09b
dangling blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
dangling blob e7a8f5a79753b9ebebb84b8c8d406316cef48aa6
dangling commit 8b31c7b18e22fddca50eb9af706b6927f2c14ddc
dangling commit 75b483ba05490108f06710e0fcd3d2e85ab94e32
dangling blob 00438efa2c06aa0599b829129850f2a5eca0d3fd
dangling commit f14813a6d31ad17c991b93b6f19ff353c342cbea
dangling commit 85cfb058693ce54607314c623162af596aa3025b
dangling blob ead0457b9cab88d57b051654169fd6b81911602e
dangling commit d05129499209565b48b609321890ecb868c3b154
dangling blob c9d75ddf04398095b2842a8332716d7f4f9d20d7
dangling blob 2b5f8d6ff4282c47204bdd59c4a59a4827f2bd46
dangling commit 69fd5e6a8733ed63293aab658d584150c0af9db2
$

Regular cleaning:

$ git gc
Enumerating objects: 11352, done.
Counting objects: 100% (11352/11352), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4140/4140), done.
Writing objects: 100% (11352/11352), done.
Total 11352 (delta 6871), reused 11352 (delta 6871)
$

End result – no change:

$ git fsck
Checking object directories: 100% (256/256), done.
Checking objects: 100% (11352/11352), done.
dangling blob 4e811469e1f97f114ed2d3e42fdcec1aedbad174
dangling blob 2384122beb433045ec091b5131d294b55fe7fb43
dangling blob db93da5493a753c01d87d665beb748ac255c8547
dangling blob af96a0d3d093de55ddcad81ed92773a179465d9f
dangling commit 659d5f247d9b3d4005d9e074f960e473bb0cf09b
dangling blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
dangling blob e7a8f5a79753b9ebebb84b8c8d406316cef48aa6
dangling commit 8b31c7b18e22fddca50eb9af706b6927f2c14ddc
dangling blob 00438efa2c06aa0599b829129850f2a5eca0d3fd
dangling commit f14813a6d31ad17c991b93b6f19ff353c342cbea
dangling commit 85cfb058693ce54607314c623162af596aa3025b
dangling blob ead0457b9cab88d57b051654169fd6b81911602e
dangling commit d05129499209565b48b609321890ecb868c3b154
dangling blob c9d75ddf04398095b2842a8332716d7f4f9d20d7
dangling blob 2b5f8d6ff4282c47204bdd59c4a59a4827f2bd46
dangling commit 69fd5e6a8733ed63293aab658d584150c0af9db2
$

Prune now:

$ git gc --prune=now
Enumerating objects: 11352, done.
Counting objects: 100% (11352/11352), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4140/4140), done.
Writing objects: 100% (11352/11352), done.
Total 11352 (delta 6871), reused 11352 (delta 6871)
$

All gone:

$ git fsck
Checking object directories: 100% (256/256), done.
Checking objects: 100% (11352/11352), done.
$

Clearing the reflog as well:

$ git reflog expire --expire=now --expire-unreachable=now --all
$ git gc --prune=now
git_gc.1551951939.txt.gz · Last modified: 2019/03/07 09:45 by rpjday