Home > other >  trying to hook up git-p4 branches properly
trying to hook up git-p4 branches properly

Time:12-04

I'm importing multiple branches from Perforce into git using git-p4, with full history, and it's working well, except that the various branches all end up "tailless". I know exactly at which revision (both as a Perforce changelist number and now as a newly-created git revision) each of them was branched off of the main trunk, and I'd very much like to have this explicitly reflected in my new git repository, but I can't seem to figure out how to achieve it.

Specifically, after importing, if I do a git log on any of my branches, it's always got a "last" (earliest) revision that has no parent. I'd like to rig it up so that revision has a parent which is a particular revision along master.

Presumably I can't just nakedly splice a branch onto master (i.e, simply set its parent link), because git hashes reflect full history, so all the hashes along my branch are likely to need adjusting, and I'm okay with that. I probably need a rebase operation of some kind, but again, I can't seem to figure out how to do it. The things I've tried so far have all tried to "replay" changes, as if to create slightly different versions of everything, and they've led to lots of merge conflicts which I don't have time to and don't want to resolve. The contents of each revision are perfectly fine (as created by git-p4); all I want to do is rejigger the way they're linked together.

Specifically, I want to change this:

enter image description here

into this:

enter image description here

I've looked at git-p4's --detect-branches option, but it doesn't look like it'll do what I want, either. If there were a way to get git p4 sync to set a parent for the "last" revision in the branch, rather than leaving it orphaned, that'd be perfect, but I'm not seeing a way.

All details of git-p4 aside, I think what I want is (in effect) a way to force a particular revision — specifically one of these orphaned (parentless) revisions at the "tail" of one of my branches — to have a parent link that's a SHA hash of my choosing, and then have that revision's hash (and all of its children's) recomputed to reflect it. I suppose I could put on a plumber's cap and write my own script to do this somehow, but I'm hoping there's a supported way.

CodePudding user response:

You can use filter-branch to do this.

  1. Clone branches separately
  2. Combine the repos using multiple remotes
  3. Use filter-branch to add parents to newer branches

From: https://labs.consol.de/development/git/2017/09/08/reunite-separate-git-repositories.html

It's probably better these days to use https://github.com/newren/git-filter-repo - but I haven't tried that.

https://github.com/newren/git-filter-repo/blob/main/Documentation/converting-from-filter-branch.md#re-grafting-history seems like it covers this case more cleanly.

  • Related