Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
git_gc [2019/03/02 08:09] – [SYNOPSIS] rpjdaygit_gc [2019/03/07 09:46] (current) – [Examples] rpjday
Line 2: Line 2:
  
 How to clean up dangling and unreachable objects. How to clean up dangling and unreachable objects.
 +
 +Links:
 +
 +  * [[https://stackoverflow.com/questions/3765234/listing-and-deleting-git-commits-that-are-under-no-branch-dangling/4528593#4528593|Stack Overflow posting]]
  
 ===== SYNOPSIS ===== ===== SYNOPSIS =====
Line 13: Line 17:
   [--force]   [--force]
   [--keep-largest-pack]   [--keep-largest-pack]
 +</code>
 +
 +===== OPTIONS =====
 +
 +In part:
 +
 +<code>
 +--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.
 +</code>
 +
 +===== Examples =====
 +
 +Current situation:
 +
 +<code>
 +$ 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
 +$
 +</code>
 +
 +Regular cleaning:
 +
 +<code>
 +$ 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)
 +$
 +</code>
 +
 +End result -- no change:
 +
 +<code>
 +$ 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
 +$
 +</code>
 +
 +Prune now:
 +
 +<code>
 +$ 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)
 +$
 +</code>
 +
 +All gone:
 +
 +<code>
 +$ git fsck
 +Checking object directories: 100% (256/256), done.
 +Checking objects: 100% (11352/11352), done.
 +$
 +</code>
 +
 +Clearing the reflog first:
 +
 +<code>
 +$ git reflog expire --expire=now --expire-unreachable=now --all
 +$ git gc --prune=now
 </code> </code>
  • git_gc.1551514152.txt.gz
  • Last modified: 2019/03/02 08:09
  • by rpjday