Understanding git gc --auto

后端 未结 3 562
既然无缘
既然无缘 2020-12-31 04:32

I\'m experimenting with fairly aggressive auto gc in Git, mainly for packing purposes. In my repos if I do git config --list I have setup

...
gc         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 04:51

    Note that gc auto is be more robust in Git 2.12.2 (released March 2017, two days ago).

    See commit a831c06 (10 Feb 2017) by David Turner (csusbdt).
    Helped-by: Jeff King (peff).
    (Merged by Junio C Hamano -- gitster -- in commit d30ec1b, 21 Mar 2017)

    gc: ignore old gc.log files

    A server can end up in a state where there are lots of unreferenced loose objects (say, because many users are doing a bunch of rebasing and pushing their rebased branches).
    Running "git gc --auto" in this state would cause a gc.log file to be created, preventing future auto gcs, causing pack files to pile up.
    Since many git operations are O(n) in the number of pack files, this would lead to poor performance.

    Git should never get itself into a state where it refuses to do any maintenance, just because at some point some piece of the maintenance didn't make progress.

    Teach Git to ignore gc.log files which are older than (by default) one day old, which can be tweaked via the gc.logExpiry configuration variable.
    That way, these pack files will get cleaned up, if necessary, at least once per day. And operators who find a need for more-frequent gcs can adjust gc.logExpiry to meet their needs.


    Note: since Git 2.17 (Q2 2018), git gc --auto will run on each git commit too.
    See "List of all commands that cause git gc --auto".

    And there is a pre-gc --auto hook associated to that command too.

提交回复
热议问题