Migration
Perforce to Git Migration
Migrate Perforce repositories to Git using git-p4, preserving branch structure, commit history, and author information.
- Teams migrating from SVN or Hg to Git
- Basic knowledge of SVN or Hg operations
- Basic Git experience
- Author information lost or mis-mapped after migration
- Large files not handled, causing repository bloat after migration
Overview
Perforce (Helix Core) is widely used in enterprise environments. git-p4 is Git's official bidirectional bridge for Perforce-to-Git migration.
Prerequisites
# Confirm git-p4 is installed
git p4 help
# Verify Perforce access
p4 info
# Check Perforce client config
p4 client -o
Preparation
1. Define Perforce Mapping
# Define the Perforce depot path to migrate
P4_PATH="//depot/main/..."
2. Author Mapping
Create an authors.txt file mapping Perforce users to Git authors:
perforce_user1 = Alice <alice@example.com>
perforce_user2 = Bob <bob@example.com>
Migration Methods
Method 1: Full Migration (Complete History)
# Full clone from Perforce
git p4 clone //depot/main/... --destination=my-repo
# With author mapping
git p4 clone --authors-file=authors.txt //depot/main/... my-repo
Method 2: Incremental Migration (Large Repos)
# Migrate recent history only
git p4 clone --max-changes=1000 //depot/main/... my-repo
# Incrementally fetch more
cd my-repo
git p4 sync
Method 3: With Labels
git p4 clone --use-client-spec --detect-labels //depot/main/... my-repo
Branch Migration
Perforce branches are typically directory-level copies, different from Git's branch model.
# Map Perforce branches to Git branches
git p4 clone //depot/main/... main-repo
# Migrate feature branch
git p4 clone //depot/feature/... --ref=refs/heads/feature feature-repo
Post-Migration Checks
# Verify commit history
git log --oneline --graph --all
# Check author info
git shortlog -sne
# Check file integrity
git fsck
# Stats
git count-objects -v
Common Issues
Large Files
# Clean up large binaries before migration
# Consider using Git LFS
git lfs track "*.psd" "*.bin"
Permission Loss
Perforce's file permission model doesn't map to Git. Recommended:
- Review sensitive file permissions after migration
- Use
.gitattributesfor necessary permissions
Continue Learning
migration/svn-to-git— SVN to Git migrationmigration/hg-to-git— Mercurial to Git migrationmigration/platform-migration— Cross-platform Git migration