1

I would like to rewrite the history of one of my repo programatically, for example using gitpython. The idea is to read a existing repository, and reapply each of its commits to a new one, after some modification:

  • different commiting time
  • splitting some commit to a submodule, if files match some pattern, adding a reference to the submodule commit
  • use a different commit message

Using gitpython, I can read the commit history tree and all the relevant informations, but I haven't found a way to commit something on a new repo, no more success when the information must be copied from another repo.

Is there a way to do this programatically? I imagine there must be a way, as it can be done more or less by hand, one commit by one.

Many thanks!

beesleep
  • 1,322
  • 8
  • 18
  • 1
    Is there a particular reason you want to use gitpython for this? In general, `git-filter-branch` provides a language-agnostic interface you can use from any language at all, including shell. – Charles Duffy Mar 21 '20 at 22:37
  • No strong reasons, but I'm not easy with git-filter-branch syntax. I don't see any way of incorporating submodule history while spliting it. I can handle the time change for all commit together, which is very easy for me in python. Basically I would feel much more in control on what I'm doing... – beesleep Mar 21 '20 at 23:04

1 Answers1

2

You can take inspiration (or directly use) newren/git-filter-repo, which is:

git filter-repo can handle splitting repository, but not necessarily adding in the same step a tree SHA1 as gitlink for a submodule repository.
Still, it can be extended to do what you need.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250