A Perforce repository can hold tens or hundreds of distinct software projects, each with its own branching model. A developer defines a “view” that tells the Perforce server which files to put into a working copy whereas a Git repository normally holds a single software project and its branches and tags (although large monolithic Git repos do exist). You typically clone the repo and, perhaps, check out submodules or subtrees.
Please follow these steps to migrate P4 to Git.
Install msysgit 1.7.10. Version 1.8.0 didn't work for me because it gave an error about being compiled without python support. Once installed, you should be able to execute "git" commands.
Install python 2.7.3. Once installed, you should be able to execute "python" commands using command prompt.
Install Perforce CLI Tools
Install the perforce command line tools if you do not already have them. Once they are installed you should be able to execute "p4" at a command prompt.
Perl is already installed in Linux and UNIX systems, on windows you will have to install it. We will use ActivePerl but not its latest version because we will need P4Perl and it only supports perl 5.12, 5.14 or 5.16.
Perforce Perl API
Download/Install Perforce Perl API here
Perforce C/C++ API
We will need this to build the Perforce Perl API. You can download it from:
Download it and extract its content. I did it under C:\.
Get the p42svn source code
Checkout the code using svn command:
svn checkout http://p42svn.tigris.org/svn/p42svn/trunk p42svn --username guestIt will ask you for a password, just hit enter.Now let's confirm if p42svn is working!
$ cd p42svn
$ perl p42svn.pl
$ Must specify at least one branch or label..
Export P4 into a dump file
We will connect to Assembla and export our p4 repo into a dump file.
Connect to p4
If you have more than 1 p4 repository in assembla just make sure you are pointing to the right repository. To check on what repo you currently are type:
$ p4 infoIf you want to change to a different repo, run this command:
$ p4 set P4CONFIG="C:\workspace_directory\p4config.txt"Check again:
$ p4 info
$ p4 login
$ Enter password:The output should looks like:
$ Your logged in.
Let's export our repo!
Make sure you are on the p42svn folder. Run the following command:
$ perl p42svn.pl --branch //depot/main=trunk --debug > Myp4.dump
Note: If you see an error about some files that can't be created because they already exist, open the p42svn.pl file with any text editor like notepad++ or sublime and go to line 1303 and edit
UNLINK =>1 to
UNLINK =>0, save it and run again the command.
If you check your p42svn folder, your Myp4.dump file is in there.
Save the git-p4.py script from GitHub into your "C:\Program Files (x86)\Git\bin" folder. To enable the "git p4" commands, you need to set up an alias. Edit the file "%USERPROFILE%.gitconfig", and add an alias section:
p4 = !'C:\\Program Files (x86)\\Git\\bin\\git-p4.py'
At this point the "git p4" commands should work.
You should now be able to clone a Perforce depot path into Git:
C:\>git p4 clone "//some/depot/path/" mygitworkspace
Importing from //some/depot/path/ into mygitworkspace
Initialized empty Git repository in C:/mygitworkspace/.git/
Doing initial import of //some/depot/path/ from revision #head into refs/remotes/p4/master
There's plenty of good documentation out there about how to use git-p4:
Git-p4 workflow follows this pattern:
Submit edits to Git ...repeat...
git p4 rebase
git p4 submit
Import your Git repository in Assembla.
Should you have any questions, don't hesitate to reach out to us at email@example.com