@matheusbsbs / matheus-bagliano / commits / d0268de6d7
Fork 0

Documentation: pruning recipe for destructive filter-branch

Add a section about how to shrink a repository's size after running git-filter-branch to remove large blobs from history. This comes up every week or so on IRC, and the commands required to handle every case are not very newbie-friendly, so hopefully writing them down somewhere leads to fewer questions. It may seem contradictory to document fallbacks for older Gits in newer docs, but we want to point people at this as a FAQ answer, and they will frequently not have the newest version installed. Thanks to Björn Steinbrink and Junio C Hamano for comments and corrections. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Feb 14, 2009 at 21:56 UTC d0268de6d755c72ff375ec95a0cc0dbd99dc31e2
1 file changed +41
Documentation/git-filter-branch.txt
+41
@@ -339,6 +339,47 @@ git filter-branch --index-filter \
339 ---------------------------------------------------------------
340
341
342 +
343 +Checklist for Shrinking a Repository
344 +------------------------------------
345 +
346 +git-filter-branch is often used to get rid of a subset of files,
347 +usually with some combination of `\--index-filter` and
348 +`\--subdirectory-filter`. People expect the resulting repository to
349 +be smaller than the original, but you need a few more steps to
350 +actually make it smaller, because git tries hard not to lose your
351 +objects until you tell it to. First make sure that:
352 +
353 +* You really removed all variants of a filename, if a blob was moved
354 + over its lifetime. `git log \--name-only \--follow \--all \--
355 + filename` can help you find renames.
356 +
357 +* You really filtered all refs: use `\--tag-name-filter cat \--
358 + \--all` when calling git-filter-branch.
359 +
360 +Then there are two ways to get a smaller repository. A safer way is
361 +to clone, that keeps your original intact.
362 +
363 +* Clone it with `git clone +++file:///path/to/repo+++`. The clone
364 + will not have the removed objects. See linkgit:git-clone[1]. (Note
365 + that cloning with a plain path just hardlinks everything!)
366 +
367 +If you really don't want to clone it, for whatever reasons, check the
368 +following points instead (in this order). This is a very destructive
369 +approach, so *make a backup* or go back to cloning it. You have been
370 +warned.
371 +
372 +* Remove the original refs backed up by git-filter-branch: say `git
373 + for-each-ref \--format="%(refname)" refs/original/ | xargs -n 1 git
374 + update-ref -d`.
375 +
376 +* Expire all reflogs with `git reflog expire \--expire=now \--all`.
377 +
378 +* Garbage collect all unreferenced objects with `git gc \--prune=now`
379 + (or if your git-gc is not new enough to support arguments to
380 + `\--prune`, use `git repack -ad; git prune` instead).
381 +
382 +
383 Author
384 ------
385 Written by Petr "Pasky" Baudis <pasky@suse.cz>,