World map

 

BM: Baca dalam Bahasa Melayu

World 10: Deep Git

Packfiles, gc and maintenance

You will learn: how Git keeps a big history small and fast, mostly by itself.

The problem

Your project has 10,000 commits. Each one made new objects. Is .git now a mess of tiny files?

Pick one answer.

Watch

Git squeezes many objects into one packfile: One file that holds many objects, squeezed together. Similar versions are saved as small differences.. Tap each step to see how.

Tap each point on the timeline.

Predict

A big file has 10 versions. Each version changed one line. In a packfile, what takes the space?

Pick one answer.

Watch

bash
git gc
git count-objects -vH
Two commands: git gc, then git count-objects -vH.

git gc is garbage collection (gc): Git tidying up: packing objects and throwing away ones nothing can reach.. It packs objects and drops junk that nothing can reach. git count-objects -vH shows the size. Git also tidies a little by itself.

Try it

gc only throws away objects that nothing can reach. Which ones does it keep?

Drag a card into a box. Or tap the card, then tap the box.

      Watch

      bash
      git maintenance start
      One command: git maintenance start.

      Big repo you use every day? git maintenance start tidies it in the background. Your computer runs the jobs on a schedule.

      Check

      Good habit, or needs work? Swipe each one.

      Swipe right for good, left for needs work. Or use the buttons.

      1 / 4

      Let Git pack objects for you

      Let Git pack objects for you

      You did it!

      You can now explain packfiles and let Git tidy up for you.

      Go deeper (optional)

      Packfiles live in .git/objects/pack. git gc --prune=now drops unreachable objects at once, with no grace time. git maintenance stop turns the background jobs off. git maintenance run --task=gc runs one job now. Git 3.0 removes the old git pack-redundant command.