5

I'm busy converting all my existing SVN repositories to Git, and at the same time also take the opportunity to use Git's ability to easily rewrite some history. For this I'm also using git filter-repo, to get rid of unwanted files and do some standard renaming via scripts. (note: they're all solo repositories only I work in, so no history altering disclaimers are needed, I know the caveats :) )

filter-repo works beautifully (with the Python scripting capabilities plus it's much faster than filter-branch), but it creates replace commits. Once the repo restructuring is done I'd like to get rid of all these replace commits again to really bake in the changed history. And preferably via a script since I've got lots of repos with lots of commits. I however turned up empty handed when googling for how to do this...

The reason for this: my Git command line client isn't bothered by this, but my GUI (SmartGit for Windows) keeps nagging that it doesn't support replace commits (it detected refs/replace-refs it says). It displays the repo contents OK anyway, and I can continue from there filling in missing commit messages, do some more cleanup etc., but I didn't look further yet so who knows what it will eventually break?

I already found a workaround by pushing each repo to an empty repo added to a local Gitea server, then just deleting the local repo and cloning it back to local. While I can live with that for the rest of my conversion journey, I keep wondering if I can/could have done it more efficient?

Carl Colijn
  • 1,205
  • 7
  • 21
  • 1
    If `git filter-repo` does not have an option for this (I would be a bit surprised if it *doesn't* but it is still a work in progress and I haven't actually *looked*), you can just run a final mostly-no-op (no filters, other than --tag-name-filter if you have tag names) `git filter-branch` at the end to "cement" all the replacements. – torek Oct 08 '20 at 22:36
  • @torek: it turns out it does indeed; see VonC's answer. And it certainly seems that most any action you undertake with the repo using tools that don't support replace-refs will cement in the replacements, but I was a bit unsure whether it would unknowingly break something... Uploading to a local Gitea server works for me (and cloning it freshly back), as well as a commit message change on an older commit using SmartGit (I suppose it invokes filter-branch for me under the hood). But both are relatively slow and/or manual actions; therefore my question. Thanks anyway! – Carl Colijn Oct 09 '20 at 08:44

1 Answers1

4

If the refs/replace-refs are problematic, you could run your filter-repo command with the
--replace-refs option.

Try it with:

--replace-refs update-no-add
# or
--replace-refs delete-no-add

See if there are still refs/replace-refs objects after the filter-repo execution then.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 1
    Thanks for that! I so far looked at the overall docu for filter-repo at https://github.com/newren/git-filter-repo/blob/main/Documentation/git-filter-repo.txt, but it's very terse on this subject. Anyway, both `delete-no-add` and `update-no-add` leave a repository without any trace of replace refs. Looking at the docu I suppose `delete-and-add` will delete previous replace-refs but add new ones for the current rewrite? And that `update-no-add` will only update existing ones but not add new ones itself? – Carl Colijn Oct 09 '20 at 08:37
  • 1
    @CarlColijn I think your interpretation of those options are correct. – VonC Oct 09 '20 at 08:49