I have an automated process that creates a temporary commit and stash, does some stuff, and then pops the stash and reverts the commit.
After doing this a few times, the automated git gc
complains that there is too much stuff for it to clean up, so I'd like this process to tidy up after itself.
I don't however want to completely wipe out any other orphaned commits or stashes that might be in the repository, so git prune
and git gc --prune=now
will be more destructive than I want.
Is there a way to specifically delete one commit or stash that is no longer accessible?
Try first to
git config --global gc."refs/stash".reflogExpireUnreachable now
in order to configure the removal of reflog entries, limited to stash, older than this time and are not reachable from the current tip.Then a
git reflog expire
would not be too destructive (as opposed to agit gc --prune=now
)For the rest, you can rely on
git maintenance
, (introduced with Git 2.29, Q4 2020).Since Git 2.31, Q1 2021, it knows how to schedule packing refs cleanup.
See this article by Brooke Kuhlmann for illustration.