contrib / fast-import / git-p4.txton commit Doc updates (a396b29)
   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" or "git-p4 rebase". Submitting changes from Git back
   8to Perforce is done 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 (remotes/p4 actually), create a
  24master branch off it and check it out. If you want the entire history (not just
  25the head revision) then you 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
  52Incremental Imports
  53===================
  54
  55After an initial import you can easily synchronize your git repository with
  56newer changes from the Perforce depot by just calling
  57
  58  git-p4 sync
  59
  60in your git repository. By default the "p4" branch is updated.
  61
  62It is recommended to run 'git repack -a -d -f' from time to time when using
  63incremental imports to optimally combine the individual git packs that each
  64incremental import creates through the use of git-fast-import.
  65
  66
  67A useful setup may be that you have a periodically updated git repository
  68somewhere that contains a complete import of a Perforce project. That git
  69repository can be used to clone the working repository from and one would
  70import from Perforce directly after cloning using git-p4. If the connection to
  71the Perforce server is slow and the working repository hasn't been synced for a
  72while it may be desirable to fetch changes from the origin git repository using
  73the efficient git protocol. git-p4 supports this through
  74
  75  git-p4 sync --with-origin
  76
  77or
  78
  79  git-p4 rebase --with-origin
  80
  81In that case "git fetch origin" is called and if it turns out that the origin
  82branch is newer than the git "p4" import branch then the latter is updated from
  83the former and the direct import from Perforce is resumed, which will result in
  84fewer changes to be imported using the slower perforce connection.
  85
  86Updating
  87========
  88
  89A common working pattern is to fetch the latest changes from the Perforce depot
  90and merge them with local uncommitted changes. The recommended way is to use
  91git's rebase mechanism to preserve linear history. git-p4 provides a convenient
  92
  93  git-p4 rebase
  94
  95command that calls git-p4 sync followed by git rebase to rebase the current
  96working branch.
  97
  98Submitting
  99==========
 100
 101git-p4 has support for submitting changes from a git repository back to the
 102Perforce depot. This requires a Perforce checkout separate to your git
 103repository. To submit all changes that are in the current git branch but not in
 104the "p4" branch (or "origin" if "p4" doesn't exist) simply call
 105
 106    git-p4 submit
 107
 108in your git repository. If you want to submit changes in a specific branch that
 109is not your current git branch you can also pass that as an argument:
 110
 111    git-p4 submit mytopicbranch
 112
 113You can override the reference branch with the --origin=mysourcebranch option.
 114
 115If a submit fails you may have to "p4 resolve" and submit manually. You can
 116continue importing the remaining changes with
 117
 118  git-p4 submit --continue
 119
 120After submitting you should sync your perforce import branch ("p4" or "origin")
 121from Perforce using git-p4's sync command.
 122
 123If you have changes in your working directory that you haven't committed into
 124git yet but that you want to commit to Perforce directly ("quick fixes") then
 125you do not have to go through the intermediate step of creating a git commit
 126first but you can just call
 127
 128  git-p4 submit --direct
 129
 130
 131Example
 132=======
 133
 134# Clone a repository
 135  git-p4 clone //depot/path/project
 136# Enter the newly cloned directory
 137  cd project
 138# Do some work...
 139  vi foo.h
 140# ... and commit locally to gi
 141  git commit foo.h
 142# In the meantime somebody submitted changes to the Perforce depot. Rebase your latest
 143# changes against the latest changes in Perforce:
 144  git-p4 rebase
 145# Submit your locally committed changes back to Perforce
 146  git-p4 submit
 147# ... and synchronize with Perforce
 148  git-p4 rebase
 149
 150
 151Implementation Details...
 152=========================
 153
 154* Changesets from Perforce are imported using git fast-import.
 155* The import does not require anything from the Perforce client view as it just uses
 156  "p4 print //depot/path/file#revision" to get the actual file contents.
 157* Every imported changeset has a special [git-p4...] line at the
 158  end of the log message that gives information about the corresponding
 159  Perforce change number and is also used by git-p4 itself to find out
 160  where to continue importing when doing incremental imports.
 161  Basically when syncing it extracts the perforce change number of the
 162  latest commit in the "p4" branch and uses "p4 changes //depot/path/...@changenum,#head"
 163  to find out which changes need to be imported.
 164* git-p4 submit uses "git rev-list" to pick the commits between the "p4" branch
 165  and the current branch.
 166  The commits themselves are applied using git diff/format-patch ... | git apply
 167