1git-p4 - Perforce <-> Git converter using git-fast-import 2 3Usage 4===== 5 6git-p4 supports two main modes: Importing from Perforce to a Git repository is 7done using "git-p4 sync". Submitting changes from Git back to Perforce is 8done using "git-p4 submit". 9 10Importing 11========= 12 13You can simply start with 14 15 git-p4 clone //depot/path/project 16 17or 18 19 git-p4 clone //depot/path/project myproject 20 21This will create an empty git repository in a subdirectory called "project" (or 22"myproject" with the second command), import the head revision from the 23specified perforce path into a git "p4" branch, create a master branch off it 24and check it out. If you want the entire history (not just the head revision) then 25you can simply append a "@all" to the depot path: 26 27 git-p4 clone //depot/project/main@all myproject 28 29 30 31If you want more control you can also use the git-p4 sync command directly: 32 33 mkdir repo-git 34 cd repo-git 35 git init 36 git-p4 sync //path/in/your/perforce/depot 37 38This will import the current head revision of the specified depot path into a 39"p4" branch of your git repository. You can use the --branch=mybranch option 40to use a different branch. 41 42If you want to import the entire history of a given depot path just use 43 44 git-p4 sync //path/in/depot@all 45 46To achieve optimal compression you may want to run 'git repack -a -d -f' after 47a big import. This may take a while. 48 49Support for Perforce integrations is still work in progress. Don't bother 50trying it unless you want to hack on it :) 51 52For convenience there's also the git-p4 clone command that works similar to 53git-clone and combines the creation of the git repository with the the initial 54import and the branch setup 55 56Incremental Imports 57=================== 58 59After an initial import you can easily synchronize your git repository with 60newer changes from the Perforce depot by just calling 61 62 git-p4 sync 63 64in your git repository. By default the "p4" branch is updated. 65 66It is recommended to run 'git repack -a -d -f' from time to time when using 67incremental imports to optimally combine the individual git packs that each 68incremental import creates through the use of git-fast-import. 69 70Updating 71======== 72 73A common working pattern is to fetch the latest changes from the Perforce depot 74and merge them with local uncommitted changes. The recommended way is to use 75git's rebase mechanism to preserve linear history. git-p4 provides a convenient 76 77 git-p4 rebase 78 79command that calls git-p4 sync followed by git rebase to rebase the current 80working branch. 81 82Submitting 83========== 84 85git-p4 has support for submitting changes from a git repository back to the 86Perforce depot. This requires a Perforce checkout separate to your git 87repository. To submit all changes that are in the current git branch but not in 88the "p4" branch (or "origin" if "p4" doesn't exist) simply call 89 90 git-p4 submit 91 92in your git repository. If you want to submit changes in a specific branch that 93is not your current git branch you can also pass that as an argument: 94 95 git-p4 submit mytopicbranch 96 97You can override the reference branch with the --origin=mysourcebranch option. 98 99If a submit fails you may have to "p4 resolve" and submit manually. You can 100continue importing the remaining changes with 101 102 git-p4 submit --continue 103 104After submitting you should sync your perforce import branch ("p4" or "origin") 105from Perforce using git-p4's sync command. 106 107 108Example 109======= 110 111# Clone a repository 112 git-p4 clone //depot/path/project 113# Enter the newly cloned directory 114 cd project 115# Do some work... 116 vi foo.h 117# ... and commit locally to gi 118 git commit foo.h 119# In the meantime somebody submitted changes to the Perforce depot. Rebase your latest 120# changes against the latest changes in Perforce: 121 git-p4 rebase 122# Submit your locally committed changes back to Perforce 123 git-p4 submit 124# ... and synchronize with Perforce 125 git-p4 rebase 126 127