use p4CmdList() to get file contents in Python dicts. This is more robust.
[fast-export/fast-export-unix-compliant.git] / git-p4.txt
blobc315158d8d7eb110b927c920f0fe348ff612054f
1 git-p4 - Perforce <-> Git converter using git-fast-import
3 Usage
4 =====
6 git-p4 supports two main modes: Importing from Perforce to a Git repository is
7 done using "git-p4 sync" or "git-p4 rebase". Submitting changes from Git back
8 to Perforce is done using "git-p4 submit".
10 Importing
11 =========
13 You can simply start with
15   git-p4 clone //depot/path/project
19   git-p4 clone //depot/path/project myproject
21 This will create an empty git repository in a subdirectory called "project" (or
22 "myproject" with the second command), import the head revision from the
23 specified perforce path into a git "p4" branch (remotes/p4 actually), create a
24 master branch off it and check it out. If you want the entire history (not just
25 the head revision) then you can simply append a "@all" to the depot path:
27   git-p4 clone //depot/project/main@all myproject
31 If you want more control you can also use the git-p4 sync command directly:
33   mkdir repo-git
34   cd repo-git
35   git init
36   git-p4 sync //path/in/your/perforce/depot
38 This 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
40 to use a different branch.
42 If you want to import the entire history of a given depot path just use
44   git-p4 sync //path/in/depot@all
46 To achieve optimal compression you may want to run 'git repack -a -d -f' after
47 a big import. This may take a while.
49 Support for Perforce integrations is still work in progress. Don't bother
50 trying it unless you want to hack on it :)
52 Incremental Imports
53 ===================
55 After an initial import you can easily synchronize your git repository with
56 newer changes from the Perforce depot by just calling
58   git-p4 sync
60 in your git repository. By default the "p4" branch is updated.
62 It is recommended to run 'git repack -a -d -f' from time to time when using
63 incremental imports to optimally combine the individual git packs that each
64 incremental import creates through the use of git-fast-import.
67 A useful setup may be that you have a periodically updated git repository
68 somewhere that contains a complete import of a Perforce project. That git
69 repository can be used to clone the working repository from and one would
70 import from Perforce directly after cloning using git-p4. If the connection to
71 the Perforce server is slow and the working repository hasn't been synced for a
72 while it may be desirable to fetch changes from the origin git repository using
73 the efficient git protocol. git-p4 supports this setup by calling "git fetch origin"
74 by default if there is an origin branch. You can disable this using
76   git config git-p4.syncFromOrigin false
78 Updating
79 ========
81 A common working pattern is to fetch the latest changes from the Perforce depot
82 and merge them with local uncommitted changes. The recommended way is to use
83 git's rebase mechanism to preserve linear history. git-p4 provides a convenient
85   git-p4 rebase
87 command that calls git-p4 sync followed by git rebase to rebase the current
88 working branch.
90 Submitting
91 ==========
93 git-p4 has support for submitting changes from a git repository back to the
94 Perforce depot. This requires a Perforce checkout separate to your git
95 repository. To submit all changes that are in the current git branch but not in
96 the "p4" branch (or "origin" if "p4" doesn't exist) simply call
98     git-p4 submit
100 in your git repository. If you want to submit changes in a specific branch that
101 is not your current git branch you can also pass that as an argument:
103     git-p4 submit mytopicbranch
105 You can override the reference branch with the --origin=mysourcebranch option.
107 If a submit fails you may have to "p4 resolve" and submit manually. You can
108 continue importing the remaining changes with
110   git-p4 submit --continue
112 After submitting you should sync your perforce import branch ("p4" or "origin")
113 from Perforce using git-p4's sync command.
115 If you have changes in your working directory that you haven't committed into
116 git yet but that you want to commit to Perforce directly ("quick fixes") then
117 you do not have to go through the intermediate step of creating a git commit
118 first but you can just call
120   git-p4 submit --direct
123 Example
124 =======
126 # Clone a repository
127   git-p4 clone //depot/path/project
128 # Enter the newly cloned directory
129   cd project
130 # Do some work...
131   vi foo.h
132 # ... and commit locally to gi
133   git commit foo.h
134 # In the meantime somebody submitted changes to the Perforce depot. Rebase your latest
135 # changes against the latest changes in Perforce:
136   git-p4 rebase
137 # Submit your locally committed changes back to Perforce
138   git-p4 submit
139 # ... and synchronize with Perforce
140   git-p4 rebase
143 Implementation Details...
144 =========================
146 * Changesets from Perforce are imported using git fast-import.
147 * The import does not require anything from the Perforce client view as it just uses
148   "p4 print //depot/path/file#revision" to get the actual file contents.
149 * Every imported changeset has a special [git-p4...] line at the
150   end of the log message that gives information about the corresponding
151   Perforce change number and is also used by git-p4 itself to find out
152   where to continue importing when doing incremental imports.
153   Basically when syncing it extracts the perforce change number of the
154   latest commit in the "p4" branch and uses "p4 changes //depot/path/...@changenum,#head"
155   to find out which changes need to be imported.
156 * git-p4 submit uses "git rev-list" to pick the commits between the "p4" branch
157   and the current branch.
158   The commits themselves are applied using git diff/format-patch ... | git apply