A little todo note before I forget it :), based on a suggestion from Lars.
[fast-export.git] / git-p4.txt
blobff0da9d0c8339ce0c6fadda2c1f5b423627d3f1f
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, create a master branch off it
24 and check it out. If you want the entire history (not just the head revision) then
25 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.
66 Updating
67 ========
69 A common working pattern is to fetch the latest changes from the Perforce depot
70 and merge them with local uncommitted changes. The recommended way is to use
71 git's rebase mechanism to preserve linear history. git-p4 provides a convenient
73   git-p4 rebase
75 command that calls git-p4 sync followed by git rebase to rebase the current
76 working branch.
78 Submitting
79 ==========
81 git-p4 has support for submitting changes from a git repository back to the
82 Perforce depot. This requires a Perforce checkout separate to your git
83 repository. To submit all changes that are in the current git branch but not in
84 the "p4" branch (or "origin" if "p4" doesn't exist) simply call
86     git-p4 submit
88 in your git repository. If you want to submit changes in a specific branch that
89 is not your current git branch you can also pass that as an argument:
91     git-p4 submit mytopicbranch
93 You can override the reference branch with the --origin=mysourcebranch option.
95 If a submit fails you may have to "p4 resolve" and submit manually. You can
96 continue importing the remaining changes with
98   git-p4 submit --continue
100 After submitting you should sync your perforce import branch ("p4" or "origin")
101 from Perforce using git-p4's sync command.
104 Example
105 =======
107 # Clone a repository
108   git-p4 clone //depot/path/project
109 # Enter the newly cloned directory
110   cd project
111 # Do some work...
112   vi foo.h
113 # ... and commit locally to gi
114   git commit foo.h
115 # In the meantime somebody submitted changes to the Perforce depot. Rebase your latest
116 # changes against the latest changes in Perforce:
117   git-p4 rebase
118 # Submit your locally committed changes back to Perforce
119   git-p4 submit
120 # ... and synchronize with Perforce
121   git-p4 rebase
124 Implementation Details...
125 =========================
127 * Changesets from Perforce are imported using git fast-import.
128 * The import does not require anything from the Perforce client view as it just uses
129   "p4 print //depot/path/file#revision" to get the actual file contents.
130 * Every imported changeset has a special [git-p4...] line at the
131   end of the log message that gives information about the corresponding
132   Perforce change number and is also used by git-p4 itself to find out
133   where to continue importing when doing incremental imports.
134   Basically when syncing it extracts the perforce change number of the
135   latest commit in the "p4" branch and uses "p4 changes //depot/path/...@changenum,#head"
136   to find out which changes need to be imported.
137 * git-p4 submit uses "git rev-list" to pick the commits between the "p4" branch
138   and the current branch.
139   The commits themselves are applied using git diff-tree ... | patch -p1