0

I am in the process of merging multiple git repositories, and mostly happy with the result except a few quirks.

I merged three repositories into one by first using git filter-repo to move individual git repos into subdirectories. I then performed a git pull with merge ort strategy (with --allow-unrelated-histories flag) from those local folders. Now my new "merged" git repo has the three subdirectories. But the commits for the individual repos are not visible from the root level without the --follow flag, or explicitly cd into the directory and then looking for the commit. For example, git show <commit-sha>, where commit-sha came from subdirectory foo for example is only visible inside that subdirectory OR by using --follow flag with git log.

I'm happy with the fact that I still have the history for each of these subdirectories, but I it would make life much simpler if I could probe the repository history without special flags or entering particular directories. I must note that I don't particularly care about maintaining the same SHAs as the old repos, but interested in the histories. How do I make that happen?

rookie
  • 1,168
  • 3
  • 14
  • 25
  • It looks like your question might be the same as ["How to merge history from unrelated repositories"](https://stackoverflow.com/questions/47162420/how-to-merge-history-from-unrelated-repositories), which also wants the histories to be interleaved. (With your unrelated `git pull`, it makes sense that your files wouldn't show up in other directories, since you'd have a lot of history rewriting to do for new parents and fuller trees in effectively every commit.) Missing there is a discussion of [`git subtree`](https://www.atlassian.com/git/tutorials/git-subtree), which might do what you want. – Jeff Bowman Nov 01 '22 at 19:44
  • I believe I'm exactly at the point where I'm interested in interleaved histories. To clarify, all my files are in the right place and the histories as well, it's just that they are not "merged" or interleaved. Any ideas how subtree might help here – rookie Nov 01 '22 at 19:59
  • I've read about `git subtree` but not used it myself well enough to construct an answer around it. Another alternative would be to `git rebase` based on your merge, but you'd have to sort your commits manually based on their dates (not fun), and that model doesn't really preserve any sorts of branches well (assuming you use branches to develop nontrivial features in each of the repos). – Jeff Bowman Nov 02 '22 at 18:27

1 Answers1

1

An alternative way to import histories is to use a tool like Copybara or FBShipIt.

The way these tools work is by copying the commits from one repository to another repository, making changes to the tree in the process. This allows you to create a combined linear history of multiple repositories, without branches, if that’s what you want. You can copy into subtrees, move files around, and you can even copy bidirectionally (i.e. copy new commits back from the monorepo to the individual repos).

The advantage is that it’s much easier to browse history. The disadvantage—well, it’s a bit of an adventure trying to use these tools.

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415