How to skip "Loose Object" popup when running 'git gui'

24,483

Solution 1

Since nobody had yet an answer, I looked into the code to see how to remove the code which shows up that dialog. I found the hint_gc procedure which does it and the place where it is called. At the same time I noticed that late 2011 there was added a configuration option for disabling the dialog. This change (part of git-gui 0.16.0) was merged to Git's mainline on 2011-12-14.

So if you use Git v1.7.9 or newer, you can disable the warning dialog with the following command:

git config --global gui.gcwarning false

If you are using an older version, then you can edit /lib/git-core/git-gui and remove the after 1000 hint_gc line, or edit /usr/share/git-gui/lib/database.tcl and remove the body of the hint_gc procedure. (These file paths are on Cygwin - on other environments the files might be in a different locations. For Windows it is c:\Program Files\Git\mingw64\libexec\git-core\git-gui.tcl)

Solution 2

Update: git prune would "solve" the issue, in that it will remove those loose objects
(git gc calls git prune, but only for loose objects older than two weeks, by default).
However, as the OP Michael Donohue mentions in the comments:

I do like the safety aspect of keeping the loose objects around for two weeks, should I want to go back and look at some old revisions, so I don't really like this solution.
I am not having any trouble with the size or performance of git, it is just 'git gui' that insists on asking me to compress the database, even when compressing the database would have no effect.


Original answer:

The problem of "git gc" not removing all loose objects has been reported before (late 2008, ""git gc" doesn't seem to remove loose objects any more"

git gc only removes loose objects older than two weeks, if you really want to remove them now, run git prune.
But make sure no other git process can be active when you run it, or it could possibly step on something.

"git gc" will unpack objects that have become unreachable and were currently in packs.
As a result, the amount of disk space used by a git repository can actually go up dramatically after a "git gc" operation, which could be surprising for someone who is running close to full on their filesystem, deletes a number of branches from a tracking repository, and then does a "git gc" may get a very unpleasant surprise.

[Example:] Old branches are reserved via a tag such as next-20081204.
If you update the your local copy of the linux-next repository every day, you will accumulate a large number of these old branch tags.
If you then delete a whole series of them, and run git-gc, the operation will take quite a while, and the number of blocks and inodes used will grow significantly.

They will disappear after a "git prune", but when I do this housekeeping operation, I've often wished for a --yes-I-know-what-I-am-doing-and-it's-unsafe-but-just-drop-the-unreachable-objects-cause-this-is-just-a-tracking-repository option to "git gc".

So in your case, would a "git prune" be helpful?

(possibly with using "now" in the gc.pruneexpire config variable, needed for the above behavior to happen).


You also have (from the same thread):

repack -a -d -l

Notice the lowercase 'a'.

git-gc calls repack with uppercase 'A' which is what causes the unreachable objects to be unpacked. Little 'a', is for people who know what they are doing, and want git to just drop unreachable objects.

Solution 3

When "Loose Object" popup I know it's time to run git's garbage collector:

git gc

After that the popup goes away.

Update: (due to T.E.D.'s suggestion)

I extracted the below routine from git/share/git-gui/lib/database.tcl
You can modify it to meet your needs.

proc hint_gc {} {
    set object_limit 8
    if {[is_Windows]} {
        set object_limit 1
    }

    set objects_current [llength [glob \
        -directory [gitdir objects 42] \
        -nocomplain \
        -tails \
        -- \
        *]]

    if {$objects_current >= $object_limit} {
        set objects_current [expr {$objects_current * 256}]
        set object_limit    [expr {$object_limit    * 256}]
        if {[ask_popup \
            [mc "This repository currently has approximately %i loose objects.

To maintain optimal performance it is strongly recommended that you compress the database when more than %i loose objects exist.

Compress the database now?" $objects_current $object_limit]] eq yes} {
            do_gc
        }
    }
}

Solution 4

Hmmmm....I don't see a command-line argument for that in the docs.

I suppose you could always pull down its source, take out the code for the dialog, and rebuild.

Share:
24,483
Michael Donohue
Author by

Michael Donohue

Updated on July 08, 2022

Comments

  • Michael Donohue
    Michael Donohue almost 2 years

    When I run 'git gui' I get a popup that says

    This repository currently has approximately 1500 loose objects.
    

    It then suggests compressing the database. I've done this before, and it reduces the loose objects to about 250, but that doesn't suppress the popup. Compressing again doesn't change the number of loose objects.

    Our current workflow requires significant use of 'rebase' as we are transitioning from Perforce, and Perforce is still the canonical SCM. Once Git is the canonical SCM, we will do regular merges, and the loose objects problem should be greatly mitigated.

    In the mean time, I'd really like to make this 'helpful' popup go away.

  • T.E.D.
    T.E.D. almost 15 years
    Doesn't clicking OK in the dialog do just that? If gc didn't get rid of all the loose objects he'd still get the dialog.
  • Michael Donohue
    Michael Donohue almost 15 years
    I've clicked 'OK' and I've run 'git gc' from the command line - they both get me down to 250, but doing it again makes no further progress.
  • Nick Dandoulakis
    Nick Dandoulakis almost 15 years
    I know it's weird but cleaning the base from gui sometimes leaves loose objects. I close the gui, run git-gc, and then all garbage are gone.
  • Michael Donohue
    Michael Donohue almost 15 years
    Changing the tcl fixes it - I just upped the windows limit to 10 * 250. Thanks!
  • David Dombrowsky
    David Dombrowsky over 14 years
    very helpful comment. That annoying "loose object" message was getting really annoying. Where does that count come from anyway? The output of git-fsck, perhaps?
  • shedd
    shedd about 12 years
    thanks - i also had loose objects that git gc wasn't removing - git prune was the answer.
  • Nicholas Orlowski
    Nicholas Orlowski about 11 years
    I did a git prune outside of any repository and it cleared up some of the objects. Then I went into the problem repository and did a git prune and all problems were gone.
  • sashoalm
    sashoalm about 7 years
    Can we increase after 1000 hint_gc so the warning happens after 10000 loose objects?
  • HankCa
    HankCa over 6 years
    @sashoalm I agree. Its there for a reason.
  • Josh Mc
    Josh Mc almost 6 years
    Wondering what exactly the good reasons are, that dialog is such a pain, without good reasons clearly explained, I am certainly very tempted to just whack in the above command.
  • fuglede
    fuglede over 5 years
    @sashoalm: Maybe this is what you mean, but the "1000" of after 1000 refers to the number of milliseconds to wait until the dialog is shown. By increasing it to "10000", the dialog will still appear, but it will take 10 seconds for it to do so instead.
  • fuglede
    fuglede over 5 years
    However, as mentioned in @NickDandoulakis's answer, database.tcl contains the definition of the limit and can be increased to make the dialog less frequent.
  • Eike
    Eike over 4 years
    "git prune" solves the problem OP (and I) had: " I've done this before, and it reduces the loose objects to about 250, but that doesn't suppress the popup."
  • VonC
    VonC over 4 years
    @Eike does a git gc suggested below get rid of the popup (as stated below)?
  • Eike
    Eike over 4 years
    @VonC I only tried "git prune", and this did get rid of the popup for me.
  • usr
    usr about 4 years
    It seems like a good idea to unpack loose objects because those objects will go away within 2 weeks. So if you can wait for that period of time that makes sense.
  • raphael
    raphael about 4 years
    for me running git gc from the command line solved the problem... just clicking ok in git gui somehow did not do the trick...
  • AlainD
    AlainD over 3 years
    Better deal with the problem than disable the warning. Close Git GUI, open Git Bash and run the command git gc --aggressive. Now re-open Git GUI.
  • tjalling
    tjalling almost 3 years
    @AlainD git already does garbage collection on its own every now and then, as part of other git commands, when it deems it necessary. So I'd argue git gui's warning and the user manually running git gc are (typically) unnecessary, and unnecessarily opinionated of git gui.