GIT-P4(1) | Git Manual | GIT-P4(1) |
git-p4 - Import from and submit to Perforce repositories
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>]
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.
$ git p4 clone //depot/path/project
$ cd project $ vi foo.h $ git commit -a -m "edited foo.h"
$ git p4 rebase
$ git p4 submit
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
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.
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
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
To specify a single commit or a range of commits, use:
$ git p4 submit --commit <sha1> $ git p4 submit --commit <sha1..sha1>
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.
To shelve changes instead of submitting, use --shelve and --update-shelve:
$ git p4 submit --shelve $ git p4 submit --update-shelve 1234 --update-shelve 2345
Unshelving will take a shelved P4 changelist, and produce the equivalent git commit in the branch refs/remotes/p4-unshelved/<changelist>.
The git commit is created relative to the current origin revision (HEAD by default). A parent commit is created based on the origin, and then the unshelve commit is created based on that.
The origin revision can be changed with the "--origin" option.
If the target branch in refs/remotes/p4-unshelved already exists, the old one will be renamed.
$ git p4 sync $ git p4 unshelve 12345 $ git show p4-unshelved/12345 <submit more changes via p4 to the same files> $ git p4 unshelve 12345 <refuses to unshelve until git is in sync with p4 again>
All commands except clone accept these options.
--git-dir <dir>
-v, --verbose
These options can be used in the initial clone as well as in subsequent sync operations.
--branch <ref>
By default a <ref> not starting with refs/ is treated as the name of a remote-tracking branch (under refs/remotes/). This behavior can be modified using the --import-local option.
The default <ref> is "master".
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>
--changes-block-size <n>
--keep-path
--use-client-spec
-/ <path>
These options can be used in an initial clone, along with the sync options described above.
--destination <directory>
--bare
These options can be used to modify git p4 submit behavior.
--origin <commit>
-M
--preserve-user
--export-labels
-n, --dry-run
--prepare-p4-only
--shelve
--update-shelve CHANGELIST
--conflict=(ask|skip|quit)
--branch <branch>
--commit (<sha1>|<sha1>..<sha1>)
--disable-rebase
--disable-p4sync
The p4-pre-submit hook is executed if it exists and is executable. The hook takes no parameters and nothing from standard input. Exiting with non-zero status from this script prevents git-p4 submit from launching. It can be bypassed with the --no-verify command line option.
One usage scenario is to run unit tests in the hook.
The p4-prepare-changelist hook is executed right after preparing the default changelist message and before the editor is started. It takes one parameter, the name of the file that contains the changelist text. Exiting with a non-zero status from the script will abort the process.
The purpose of the hook is to edit the message file in place, and it is not suppressed by the --no-verify option. This hook is called even if --prepare-p4-only is set.
The p4-changelist hook is executed after the changelist message has been edited by the user. It can be bypassed with the --no-verify option. It takes a single parameter, the name of the file that holds the proposed changelist text. Exiting with a non-zero status causes the command to abort.
The hook is allowed to edit the changelist file and can be used to normalize the text into some project standard format. It can also be used to refuse the Submit after inspect the message file.
The p4-post-changelist hook is invoked after the submit has successfully occurred in P4. It takes no parameters and is meant primarily for notification and cannot affect the outcome of the git p4 submit action.
These options can be used to modify git p4 rebase behavior.
--import-labels
--origin
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.
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.
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 .
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.
The following config settings can be used to modify git p4 behavior. They all are in the git-p4 section.
git-p4.user
git-p4.password
git-p4.port
git-p4.host
git-p4.client
git-p4.retries
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
git-p4.pathEncoding
git-p4.metadataDecodingStrategy
git-p4.metadataFallbackEncoding
git-p4.largeFileSystem
git config git-p4.largeFileSystem GitLFS
git-p4.largeFileExtensions
git-p4.largeFileThreshold
git-p4.largeFileCompressedThreshold
git-p4.largeFilePush
git-p4.keepEmptyCommits
git-p4.mapUser
git config --add git-p4.mapUser "p4user = First Last <mail@address.com>"
A mapping will override any user information from P4. Mappings for multiple P4 user can be defined.
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
git-p4.disableRebase
git-p4.disableP4Sync
Part of the git(1) suite
06/06/2021 | Git 2.32.0 |