问题
I did:
git p4 clone //depot/path/to/project/trunk/@all project
to create the master
branch of project
. Now I want to clone //depot/path/to/project/release
to the release
branch of project
. How is that done?
UPDATE: Using --detect-branches
doesn't work, either. It reports that it's updating two branches (when there are really three branches) but git branch
reports only master exists.
回答1:
Here are my setup notes from when I was using git-p4. It might be helpful:
Download the p4 linux client. Store the file in
~/bin
or/usr/local/bin
andchmod +x
Setup git-p4 as root
chmod 755 /usr/share/doc/git/contrib/fast-import/git-p4 ln -s /usr/share/doc/git/contrib/fast-import/git-p4 /usr/local/bin
Define Git globals for git-p4
git config --global alias.p4 '!git-p4' git config --global git-p4.detectRenames true git config --global git-p4.detectCopies true
Set defines for direct 'p4' usage
export P4PORT=SERVER_NAME:PORT_NUMBER
Set login credentials
export P4USER=USER_NAME export P4PASSWD=PASSWORD
Select Perforce branches using P4 'client'
Run the 'p4 client' command, and add only the paths/branches you are interested in. If you want to name the client work space you can add an optional CLIENT_NAME argument to the end of the command. This will allow you to use different client definitions on the same machine.
$ p4 client [CLIENT_NAME] View: //depot/main... //CLIENT_NAME/main... //depot/patch... //CLIENT_NAME/patch... //depot/dev... //CLIENT_NAME/dev...
Clone the repository
Simple import
git p4 clone --use-client-spec --detect-branches //depot@all GIT_DIR
Advanced import
git init PROJ; cd PROJ/ git config git-p4.branchList main:patch git config --add git-p4.branchList main:dev git p4 clone --use-client-spec //depot@all .
Submit Changes Back to Perforce
In order to submit changes to Perforce, it requires a client workspace, separate from the git working tree. It is recommend that the workspace is on the same file system your Perforce git working directory.
Additionally, a reference to the workspace path is stored on the Perforce server, and will be used during the
p4 submit
command.The first step is to create the local client workspace.
CLIENT_NAME
is an optional argument. If you do not define it, p4 will use your host name.p4 client [CLIENT_NAME]
You will be moved to a file editor before completing the p4 command. This lets you change any of the client settings before they are sent to the server. You must change the
Root
value to a new directory outside of your git tree (e.g. ../p4-working) Also, verify theOwner
andClient
values before exiting. These values are taking from your environment, and can not be changed in the editor.p4 clients | grep USERNAME
If you did not use the default client name, it must be defined in your local git config:
git config git-p4.client CLIENT_NAME
When you are ready to push your code changes, use the commands:
git p4 rebase git p4 submit
You can remove clients from the sever when no longer in use:
p4 client -d CLIENT_NAME
回答2:
I believe "detect branches" relies on you having a branch mapping with the same name as the branch path in your depot. If that is not the case, you probably need to use the suggested method of defining the git-p4.branchList
config value in an empty git repo before running the git-p4 clone command.
回答3:
Horribly late answer, but there's so little documentation on git-p4 that I hope it's still useful.
I also struggled to add branches to an existing repository, and never got the detect-branches
magic to work with branch mappings.
I had a little more success doing it in stages manually, explicitly telling git-p4 which path to import and using the --branch
option. I believe I also manually created the release
branch in the existing repository before running that.
For this question, that would be git p4 sync //depot/path/to/project/release --branch=release
I believe this would work using clone
too, as clone is mostly just sync behind the scenes in the git-p4 code, but once you already have a repository, I think sync
would be safer.
来源:https://stackoverflow.com/questions/15305357/how-to-clone-branch-with-git-p4