从Perforce单向同步多版本到Git分支的问题及git-p4执行异常求助
Hey there, let's tackle your three core questions first, then fix the sync issue you're facing with your current setup.
1. Can I sync two Perforce directories to different Git branches simultaneously?
Absolutely, but your current configuration has a critical mistake in how you're mapping Perforce paths to Git branches. The git-p4.branchList setting needs explicit mappings between your Perforce depot paths and their target Git branches—not just shorthand names like Rel1:Rel2.
Fix for your setup:
First, update your Perforce client spec to explicitly include both target paths (avoid broad //depot/... which confuses branch detection):
//depot/Rel1/cla/... //myws/Rel1/cla/... //depot/Rel2/cla/... //myws/Rel2/cla/...
Then reconfigure your Git-p4 settings with the correct branch mappings:
git init git config git-p4.useClientSpec true git config git-p4.client myws git config git-p4.branchUser myusername # Map Perforce paths directly to Git branches git config git-p4.branchList //depot/Rel1/cla:master,//depot/Rel2/cla:branch1
Now run the sync with branch detection:
git p4 sync --detect-branches --verbose
This will create remote branches remotes/p4/master and remotes/p4/branch1. To pull them into local branches:
git checkout -b master remotes/p4/master git checkout -b branch1 remotes/p4/branch1
2. Can I sync based on Perforce tags instead of version directories?
Yes, git-p4 supports syncing from Perforce tags. Here's how to do it:
Option 1: Sync a tag to an existing Git branch
First, get the revision number associated with your Perforce tag:
p4 label -o Rel1_v1.0 | grep Revision # Output example: Revision: 1998133
Then sync that specific revision to your target Git branch:
git p4 sync //depot/Rel1/cla@1998133 --branch master
Option 2: Import Perforce tags as Git tags
If you want to mirror Perforce tags directly in Git, use:
git p4 tag //depot/tags/Rel1_v1.0
This will create a Git tag matching the Perforce tag's name and content.
3. Can I sync only incremental changes weekly?
100%—git-p4 automatically tracks the last synced Perforce change number in your Git config (under git-p4.lastChange). For weekly incremental syncs, you just need to run:
git p4 sync --detect-branches
It will only pull changes made since your last sync, no full re-scans required.
Why your original setup failed:
- Incorrect
branchList: YourRel1:Rel2mapping didn't tell git-p4 which Git branches to map to which Perforce paths. - Overly broad client spec: Using
//depot/...made git-p4 process every file in your depot, causing the infinite runtime. - Manual changes file: Generating a combined changes list for both branches confused git-p4's branch detection logic, leading it to ignore Rel2 entirely.
内容的提问来源于stack exchange,提问作者DevOops




