Perforce is great source version tool for owner of company, because it's centralize control and can track each client behavior. But I don't like it anymore.
So I used Git to manage my local repo that is sync from perforce server. Use git to track my local commits and use p4/p4v to submit changes to Perforce server. But the work flow will complex and waste time(file always locks to read only with p4).
Few couple months passed, I found the tool git-p4 that can manage p4 repo like remote git branch. That similar like git-svn tool (
git 與 git-svn 簡單教學)
The
git-p4 is wrote by python and it integrates to
git source tree. you need turn off the compile flag(ON_PYTHON) when you compiling git.
In official build on git website, the NO_PYTHON is enable, so you can't use it with git-p4.
$ git p4
fatal: git was built without support for git-p4 (NO_PYTHON=1).
Please clone the git and switch to tag v1.9.2
$ git clone https://github.com/git/git
$ git checkout v1.9.2 -b v1.9.2
Follow INSTALL document to compile and install git, Please make sure the python already install in your environment (NO_PYTHON will turn OFF when you compile)
$ make prefix=/usr all
$ sudo make prefix=/usr install
Check your git and git-p4 are ready to use
$ git --version
git version 1.9.2
$ git-p4
usage: /usr/bin/git-p4 [options]
valid commands: clone, rollback, debug, commit, rebase, branches, sync, submit
Try /usr/bin/git-p4 --help for command specific help.
Add p4 alias to your ~/.gitconfig
[alias]
p4 = !/usr/bin/git-p4
Don't forget your p4 command and environemnt
$ export P4CLIENT=[your_client_name]
$ export P4HOST=[perforce_server_ip]:1666
$ export P4USER=[login_user_name]
$ export P4EDITOR=vim
Now, you can clone a proj from perforce.
# Clone a repository and covert all change list to git log
$ git p4 clone //depot/path/project@all myproject
# Clone a repository without log
$ git p4 clone //depot/path/project myproject
# Do some work and commit to your local git repo
$ git add foo.py
$ git commit foo.py
# Submit your local commit to remote repo (Perforce server)
# git p4 will create a change list for commit
$ git p4 submit
# Synchronize with Perforce (almost like 'git fetch' and 'get pull')
$ git p4 rebase
All done, enjoy it! :)