Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Git 2.31 Release: Maintenance Moved to Background

Git 2.31 Release: Maintenance Moved to Background

This item in japanese

By moving the Git maintenance in the background and adding reverse indexes on disk, Git 2.31, intends to make this omnipresent tool more user friendlier and faster when executing common operations like fetch and push.

Even if most of the time the automatic cleaning mechanisms of various tools are making our lives easier, there are those critical moments when a Git garbage collection (gc) stops our normal flow leaving us staring at a terminal screen. One of these situations is signaled by the following message in case of Git:

Auto packing the repository for optimum performance. You may also run "git gc" manually. See "git help gc" for more information.

After this happens, you are stuck waiting regardless of what you were doing. Needless to say, these Git maintenance operations are essential and when starting with version 2.31 there is another option: git background maintenance. This new feature allows you to keep your repository healthy while not blocking any of your interactions.

To make your interactions more efficient, Git comes with preconfigured actions that will increase its efficiency. It will prefetch the latest objects from the remote repositories and ensure that the commit-graph file is updated once an hour. Also, it will pack any loose objects and incrementally repack packed objects daily. For a deeper understanding of this feature, read its documentation.

Git stores all data as "objects": commits, trees, blobs etc.,  and stores the content of individual files. For improved storing, many objects are put into packfiles, which are essentially a concatenated stream of objects. In order to still be able to access each individual object efficiently, an index for each packfile is generated. In this way it was possible to quickly navigate from an object’s ID into its byte offset within the packfile.

The reverse binding, a mapping between locations in a packfile and the object each location is part of, called reverse index, was computed up to version 2.31, on the fly. Starting with this version, these mappings can be found in .rev files on disk, containing an array sorted by position containing object-position pairs.

By using already computed reverse indices, Git can send object bytes directly from disk much faster, helping during fetch and/or push operations. 

Currently the .rev files are not generated by default; one can enable them by running:

git config pack.writeReverseIndex true

and then repacking your repository (git repack -Ad).

Rate this Article