Getting the whole files history with git-p4 Getting the whole files history with git-p4 git git

Getting the whole files history with git-p4


Try appending "@all" to the file path. For example, this produces a single-revision repo for me:

python /usr/share/doc/git-core/contrib/fast-import/git-p4 clone --destination=master-pom \    //depot/services/master-pom/trunk/...

This command imported the full history:

python /usr/share/doc/git-core/contrib/fast-import/git-p4 clone --destination=master-pom \    //depot/services/master-pom/trunk/...@all

I tried using the example git-p4 but gave up for several reasons and wrote my own fast-import pump. It was a while back, so some of the problems may have been fixed now: but git-p4 had trouble with large changelists (such as the initial creation of a branch) (although using the client spec may have helped, I don't think I tried it) and files with the "+S" filetype modifier (which is Bad And Evil, but we used to use it). And my Python-fu wasn't up to letting me fix the issues I had.

EDIT: since someone asked for it, here it is.

https://github.com/araqnid/p4utils has several p4 things, of which p4-git-xfer is the p4->git (one-way) replicator. It has quite a few issues though, due to being mainly a personal handy-tool rather than a real piece of infrastructure.

Getting started:

p4-git-xfer clone -d $PWD/dictionary.git -n //depot/services/midoffice/dictionary/... \  trunk 'release/*' 'branch/*' \  trunk=master release/*=r* branch/*=dev/*

will clone that perforce path to a bare "dictionary.git". The first arguments after the base path are "branch specs" that tell the replicator where to find branches under the base. The later ones (with '=' symbols) are "mirror specs" that tell the replicator how to create local branches from the imported ones. The branch specs cause "refs/remotes/p4/trunk", "refs/remotes/p4/release/1.0" etc. to be created. The mirror specs force "refs/heads/master" to mirror "refs/remotes/p4/trunk", "refs/heads/r1.0" to mirror "refs/remotes/p4/release/1.0" etc. It was intended as a way to allow me to select just particular branches from those that were replicated to get propagated to clones.

It will attempt to detect how a branch is created, but that's a bit of a guess anyway with Perforce. Apart from that, it doesn't try to do any branch tracking at all: even whole-branch merges won't be written out as such, sorry.

After the initial clone, running p4-git-xfer fetch from inside the git replica will do an incremental update. The high-water-mark changelist is taken from marks/p4 within the git repo. This is a marks file that fast-import loads, so if you do any fancy footwork like using filter-branch to rewrite things, beware you may have to update this too.

It's not pretty, and has some medium-to-serious issues; I use it mainly for my own convenience, to isolate myself from Perforce problems, not as a day-to-day criticial infrastructure component. It's one-way: I generally use the p4-am script to apply patches created by git format-patch. That itself only works mostly, with general parsing nastiness, problems with end-of-file newlines, binary changes etc.


  1. install git bash (cli)
  2. install p4 cli
  3. install python 2.7
  4. get git-p4 script>> http://git.kernel.org/cgit/git/git.git/plain/git-p4.py
  5. put this script into c/program/files/git/bin/
  6. now open git bash or cmd check by typing python done, p4 done, git done, git p4,
  7. create client workspace named git .
  8. git p4 clone depo/path/@all repo/path

just in case doesnt work set path in environment variables for python if python creates problemset P4CLIENT=git


The git-p4 help is actually pretty good:

man git-p4

On Ubuntu 12.04 it is include in the git-man package.