GIT-P4(1) | Git Manual | GIT-P4(1) |
NAME¶
git-p4 - Import from and submit to Perforce repositories
SYNOPSIS¶
git p4 clone [<sync options>] [<clone options>] <p4 depot path>... git p4 sync [<sync options>] [<p4 depot path>...] git p4 rebase git p4 submit [<submit options>] [<master branch name>]
DESCRIPTION¶
This command provides a way to interact with p4 repositories using Git.
Create a new Git repository from an existing p4 repository using git p4 clone, giving it one or more p4 depot paths. Incorporate new commits from p4 changes with git p4 sync. The sync command is also used to include new branches from other p4 depot paths. Submit Git changes back to p4 using git p4 submit. The command git p4 rebase does a sync plus rebases the current branch onto the updated p4 remote branch.
EXAMPLE¶
$ git p4 clone //depot/path/project
$ cd project $ vi foo.h $ git commit -a -m "edited foo.h"
$ git p4 rebase
$ git p4 submit
COMMANDS¶
Clone¶
Generally, git p4 clone is used to create a new Git directory from an existing p4 repository:
$ git p4 clone //depot/path/project
This:
To reproduce the entire p4 history in Git, use the @all modifier on the depot path:
$ git p4 clone //depot/path/project@all
Sync¶
As development continues in the p4 repository, those changes can be included in the Git repository using:
$ git p4 sync
This command finds new changes in p4 and imports them as Git commits.
P4 repositories can be added to an existing Git repository using git p4 sync too:
$ mkdir repo-git $ cd repo-git $ git init $ git p4 sync //path/in/your/perforce/depot
This imports the specified depot into refs/remotes/p4/master in an existing Git repository. The --branch option can be used to specify a different branch to be used for the p4 content.
If a Git repository includes branches refs/remotes/origin/p4, these will be fetched and consulted first during a git p4 sync. Since importing directly from p4 is considerably slower than pulling changes from a Git remote, this can be useful in a multi-developer environment.
If there are multiple branches, doing git p4 sync will automatically use the "BRANCH DETECTION" algorithm to try to partition new changes into the right branch. This can be overridden with the --branch option to specify just a single branch to update.
Rebase¶
A common working pattern is to fetch the latest changes from the p4 depot and merge them with local uncommitted changes. Often, the p4 repository is the ultimate location for all code, thus a rebase workflow makes sense. This command does git p4 sync followed by git rebase to move local commits on top of updated p4 changes.
$ git p4 rebase
Submit¶
Submitting changes from a Git repository back to the p4 repository requires a separate p4 client workspace. This should be specified using the P4CLIENT environment variable or the Git configuration variable git-p4.client. The p4 client must exist, but the client root will be created and populated if it does not already exist.
To submit all changes that are in the current Git branch but not in the p4/master branch, use:
$ git p4 submit
To specify a branch other than the current one, use:
$ git p4 submit topicbranch
The upstream reference is generally refs/remotes/p4/master, but can be overridden using the --origin= command-line option.
The p4 changes will be created as the user invoking git p4 submit. The --preserve-user option will cause ownership to be modified according to the author of the Git commit. This option requires admin privileges in p4, which can be granted using p4 protect.
OPTIONS¶
General options¶
All commands except clone accept these options.
--git-dir <dir>
--verbose, -v
Sync options¶
These options can be used in the initial clone as well as in subsequent sync operations.
--branch <branch>
This example imports a new remote "p4/proj2" into an existing Git repository:
$ git init
$ git p4 sync --branch=refs/remotes/p4/proj2 //depot/proj2
--detect-branches
--changesfile <file>
--silent
--detect-labels
--import-labels
--import-local
--max-changes <n>
--keep-path
--use-client-spec
Clone options¶
These options can be used in an initial clone, along with the sync options described above.
--destination <directory>
--bare
-/ <path>
Submit options¶
These options can be used to modify git p4 submit behavior.
--origin <commit>
-M
--preserve-user
--export-labels
--dry-run, -n
--prepare-p4-only
--conflict=(ask|skip|quit)
--branch <branch>
Rebase options¶
These options can be used to modify git p4 rebase behavior.
--import-labels
DEPOT PATH SYNTAX¶
The p4 depot path argument to git p4 sync and git p4 clone can be one or more space-separated p4 depot paths, with an optional p4 revision specifier on the end:
"//depot/my/project"
"//depot/my/project@all"
"//depot/my/project@1,6"
"//depot/proj1@all //depot/proj2@all"
See p4 help revisions for the full syntax of p4 revision specifiers.
CLIENT SPEC¶
The p4 client specification is maintained with the p4 client command and contains among other fields, a View that specifies how the depot is mapped into the client repository. The clone and sync commands can consult the client spec when given the --use-client-spec option or when the useClientSpec variable is true. After git p4 clone, the useClientSpec variable is automatically set in the repository configuration file. This allows future git p4 submit commands to work properly; the submit command looks only at the variable and does not have a command-line option.
The full syntax for a p4 view is documented in p4 help views. git p4 knows only a subset of the view syntax. It understands multi-line mappings, overlays with +, exclusions with - and double-quotes around whitespace. Of the possible wildcards, git p4 only handles ..., and only when it is at the end of the path. git p4 will complain if it encounters an unhandled wildcard.
Bugs in the implementation of overlap mappings exist. If multiple depot paths map through overlays to the same location in the repository, git p4 can choose the wrong one. This is hard to solve without dedicating a client spec just for git p4.
The name of the client can be given to git p4 in multiple ways. The variable git-p4.client takes precedence if it exists. Otherwise, normal p4 mechanisms of determining the client are used: environment variable P4CLIENT, a file referenced by P4CONFIG, or the local host name.
BRANCH DETECTION¶
P4 does not have the same concept of a branch as Git. Instead, p4 organizes its content as a directory tree, where by convention different logical branches are in different locations in the tree. The p4 branch command is used to maintain mappings between different areas in the tree, and indicate related content. git p4 can use these mappings to determine branch relationships.
If you have a repository where all the branches of interest exist as subdirectories of a single depot path, you can use --detect-branches when cloning or syncing to have git p4 automatically find subdirectories in p4, and to generate these as branches in Git.
For example, if the P4 repository structure is:
//depot/main/... //depot/branch1/...
And "p4 branch -o branch1" shows a View line that looks like:
//depot/main/... //depot/branch1/...
Then this git p4 clone command:
git p4 clone --detect-branches //depot@all
produces a separate branch in refs/remotes/p4/ for //depot/main, called master, and one for //depot/branch1 called depot/branch1.
However, it is not necessary to create branches in p4 to be able to use them like branches. Because it is difficult to infer branch relationships automatically, a Git configuration setting git-p4.branchList can be used to explicitly identify branch relationships. It is a list of "source:destination" pairs, like a simple p4 branch specification, where the "source" and "destination" are the path elements in the p4 repository. The example above relied on the presence of the p4 branch. Without p4 branches, the same result will occur with:
git init depot cd depot git config git-p4.branchList main:branch1 git p4 clone --detect-branches //depot@all .
PERFORMANCE¶
The fast-import mechanism used by git p4 creates one pack file for each invocation of git p4 sync. Normally, Git garbage compression (git-gc(1)) automatically compresses these to fewer pack files, but explicit invocation of git repack -adf may improve performance.
CONFIGURATION VARIABLES¶
The following config settings can be used to modify git p4 behavior. They all are in the git-p4 section.
General variables¶
git-p4.user
git-p4.password
git-p4.port
git-p4.host
git-p4.client
Clone and sync variables¶
git-p4.syncFromOrigin
git-p4.branchUser
git-p4.branchList
git config git-p4.branchList main:branchA git config --add git-p4.branchList main:branchB
git-p4.ignoredP4Labels
git-p4.importLabels
git-p4.labelImportRegexp
git-p4.useClientSpec
Submit variables¶
git-p4.detectRenames
git-p4.detectCopies
git-p4.detectCopiesHarder
git-p4.preserveUser
git-p4.allowMissingP4Users
git-p4.skipSubmitEdit
git-p4.skipSubmitEditCheck
git-p4.allowSubmit
git-p4.skipUserNameCheck
git-p4.attemptRCSCleanup
git-p4.exportLabels
git-p4.labelExportRegexp
git-p4.conflict
IMPLEMENTATION DETAILS¶
05/23/2023 | Git 1.8.3.1 |