Home > Software design >  Expire orphaned git replace refs
Expire orphaned git replace refs

Time:06-05

we have a large repository here on a privately hosted Git-Lab instance. A year ago this repo was migrated from another company and the git history was rewritten in migration various reasons and there were also additional git-replace refs installed, for legacy compatibility with old documentation references.

Previously, there were hundreds of experimental branches, many never merged and worthless in the end, and the old developers were too lazy to remove them. The branches in the new repo have been cleaned up up since then but its reported size in GitLab is still showing many gigabytes. This does not make sense, a freshly cloned & git-gc'ed repository would consume only a half of that space.

Pushing "Housekeeping" function in the GitLab config does not fix it, the size remains almost the same as it has been before experimental branches were removed. The only explanation I have is the presence of the old git-replace refs which still show at some commit data, although this data is supposed to be gone now.

Dear internet, is there a good way to

  1. auto-detect such git-replace refs which point at commits which are no longer covered by any branch head, and
  2. delete them explicitly on the server?

CodePudding user response:

There isn't anything built in to Git for this, mostly (I assume) because it's obvious that the definition of "orphaned" is in the eye of the beholder. So you'll need to write your own program / script to determine which replace refs to jettison.

Note that if you're willing to have a flag day when everyone cuts over from "old repo" to "new repo", you can use git filter-branch (old, obsoleted, but still works) or git filter-repo (the hot new method that's not yet distributed with Git releases) to build a repository in which all replacements are done into a whole new history. This is a lot easier, except for the flag-day thing, and of course since the new history has new hash IDs, anything based on the original hash IDs stops working.

CodePudding user response:

  1. test -z output git -P branch -a --contains <named-ref>
  2. push the named ref with : in front to server.
  • Related