16

I have the task of migrating my team & source from git to Perforce, and I'm looking for ideas on how to move the git history into p4.

I would be happy moving master branch only. However, even that is proving problematic.

I'm using the wonderful git-p4 tool. I create an destination area in my p4 workspace, and use git p4 clone //depot/StuffFromGit to start tracking it in git-p4. I graft all my git repository's changes into the git-p4 clone. I can then git p4 submit and be done, all the changes are pushed to p4.

It works great when the git history looks like this, nice and linear:

A---B---C---D

The problem comes with multiple people working on the project. Even though they are working on master, that still creates branches that split and merge. Still, git-p4 bravely handles this:

A---B---C---E
     \--D--/

git p4 traverses OK, committing ABCDE in order (or ABDCE, either person's history first).

The problem comes when, for example, C and D both change the same file, and E is a real-honest-to-goodness merge. git p4 rebase fails here; it'll rewind the commits, but during playback it'll apply C first, then attempt D and find a conflict. It'll then stop, asking me to merge. Well, E contains the merge but it's asking me to hand-merge! 'git p4 submit' will fail in a similar way, only now it's p4 rejecting the pre-merge change.

Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging main.cpp
CONFLICT (content): Merge conflict in main.cpp
Failed to merge in the changes.
Patch failed at 0005 Changing main

So now I'm stuck. Is there a way to sanitize the git history or to get git-p4 to understand it? It's frustrating as the merges are there.

Thoughts I've had:

  • Use git filter-branch to remove all mention of conflicting files. I'd get the history comments across, though missing many file changes. With about 3000 commits in the history, I would wind up removing all of the key (busy) files' history. At the end of the filtered-files import, I'd add the missing files back by doing a final commit of the HEAD.
  • Dump the history, do a single p4 commit of the HEAD (simple but sad).
  • Not move to p4: I've worked that idea for as long as possible.

None of which are really great. Any ideas on how to git 'gt p4 rebase' or 'git p4 submit' to work?

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
  • 16
    Given git's history, that's kinda of a funny direction to be migrating. – T.E.D. Oct 15 '10 at 21:54
  • 2
    Sounds like git-p4 is trying to merge C, D **and** E, and of course failing miserably. Have you checked that you are running the latest git-p4 and if there are some patches or other people have seen the same problem? – Jakob Borg Oct 16 '10 at 17:43
  • 19
    Wow, man, I'm sorry. Sounds like you're moving like 10-15 years backwards. – Jonathan Oct 18 '10 at 13:41
  • Yes, I'm using the latest git-p4. – Graham Perks Oct 18 '10 at 17:35
  • 2
    this sounds horrible. Have you rebased chunks of history? That might make the import easier.. – Adam Dymitruk Oct 19 '10 at 18:26
  • Have you tried moving to SVN and then P4?? – pablo Oct 19 '10 at 19:41
  • I've tried rebasing, but that doesn't collapse the branches into a single line of commits. What I've done is make a single commit to p4, losing all history. :( – Graham Perks Oct 20 '10 at 13:16
  • Please tell me this decision to move from git to Perforce wasn't made by devs :) – Carl Apr 03 '12 at 21:14
  • This was originally asked in 2010. I wonder if we can get an update on that project? Anyone sane still around to report on what the end result was? (Signed: current git convert / ex-perforce user (as well as ex-cvs/ex-clearcase/ex-svn user ... but honestly, p4 was the worst of the lot (maybe even including cvs)) – michael Jul 08 '12 at 04:11
  • 1
    We got pushed to migrate the project into P4 (to match all the other teams, share code etc), and eventually did so, losing all history. Now other groups are experimenting with git again, so if I could have held out for a few more months, perhaps the pain could have been avoided. There's no happy ending here, sorry! git-p4 FTW! – Graham Perks Jul 14 '12 at 02:06
  • 1
    Happy ending update! I left the company in 2013 and have been using git ever since :) – Graham Perks Apr 19 '17 at 19:06

4 Answers4

8

The option of "just throw away the old history" is not as bad as it sounds: you can just keep your git repo alongside it forever, in case anyone needs to dig through the old stuff. Unfortunately, there is just no way to represent git's complex view of history in old-style linear systems like svn and p4.

The main reason to look back into old history is for things like 'git annotate' (I assume p4 has a similar tool). If that's all you want, then maybe what you really want to do is squash all your merge commits down to only one of their parents (so they look like a single commit instead of a merge). That's more like what svn and p4 would have recorded in their own history model, where merges just look like a single commit in the linear stream. You can probably do this with git-filter-branch or the like. Of course, this would lose all the history that happened on sub-branches... but p4 users are used to not having that information.

apenwarr
  • 10,838
  • 6
  • 47
  • 58
  • Perforce doesn't typically use sub-branches, but it can if you want to manage the branches. Then the information is there. – Br.Bill Aug 26 '15 at 19:00
2

Have you checked out the tool "tailor"? It's build for synchronizing different VCS:es. It's supposed to have Perforce-support.

As a side-note, my first reaction would be to seriously question the decision, but I guess you've already done that.

Rawler
  • 1,480
  • 1
  • 11
  • 23
0

Have you looked at Perforce Fusion?

I had a similar ask around 7-8 years ago, and we basically rallied all of the senior devs together, and told the manager pushing this idea that he was off his rocker.

That said - https://www.perforce.com/perforce/r15.3/manuals/git-fusion/

mr.buttons
  • 685
  • 1
  • 9
  • 18
-2

I think you should try with Tortoise SVN and then Hg considering the single branch update or you can say migration. Make sure you have all the dump cloned to be on the safe side. Good Luck !

NaV
  • 703
  • 4
  • 9
  • 19