| name | tools-p4-basics |
| description | Fundamental Perforce operations including sync, edit, add, delete, submit, revert, and file state management. |
Perforce Basics
Overview
Perforce (P4) is a centralized version control system optimized for large codebases and binary assets. This skill covers essential daily operations.
When to Use
- Syncing latest changes
- Editing files for modification
- Adding new files
- Deleting files
- Submitting changes
- Reverting unwanted changes
Core Concepts
File States
| State | Description | Command to Change |
|---|
| Not in depot | File exists locally but not tracked | p4 add |
| Synced | File matches depot version | - |
| Edited | Open for edit, modified locally | p4 edit then modify |
| Added | Marked for addition to depot | p4 add |
| Deleted | Marked for deletion from depot | p4 delete |
| Out of date | Depot has newer version | p4 sync |
Revision Specifiers
file.txt#3
file.txt#head
file.txt@12345
file.txt@release_1.0
file.txt@2024/01/15
file.txt@2024/01/15:14:30:00
file.txt#2,#5
file.txt@10000,@12000
Sync Operations
Basic Sync
p4 sync
p4 sync //depot/project/...
p4 sync //depot/project/file.txt
p4 sync //depot/project/...#head
p4 sync //depot/project/...@12345
p4 sync @12345
Sync Options
p4 sync -n //depot/project/...
p4 sync -f //depot/project/...
p4 sync --parallel=threads=4 //depot/project/...
p4 sync -s //depot/project/...
p4 sync //depot/project/... 2>&1 | head -50
Selective Sync
p4 sync //depot/project/....cs
p4 sync //depot/project/....prefab
p4 sync //depot/project/Assets/Scripts/...
Edit Operations
Opening Files for Edit
p4 edit file.txt
p4 edit *.cs
p4 edit Assets/Scripts/...
p4 edit -c 12345 file.txt
p4 edit -c default file.txt
Check Edit Status
p4 opened
p4 opened -c 12345
p4 opened -a //depot/project/...
p4 opened -a //depot/project/file.txt
Add Operations
Adding New Files
p4 add newfile.txt
p4 add *.cs
p4 add Assets/NewFeature/...
p4 add -c 12345 newfile.txt
p4 add -t binary+l largefile.bin
p4 add -t text+x script.sh
File Types
text
binary
unicode
symlink
+l
+w
+x
+S
+F
p4 add -t binary+l Assets/Textures/hero.psd
p4 add -t text Assets/Scripts/Player.cs
Delete Operations
Deleting Files
p4 delete file.txt
p4 delete *.bak
p4 delete -c 12345 file.txt
p4 delete //depot/project/....tmp
Handling Deleted Files
p4 files //depot/project/...@head | grep "delete change"
p4 sync //depot/project/file.txt#head-1
p4 add file.txt
Revert Operations
Reverting Changes
p4 revert file.txt
p4 revert -c 12345 //...
p4 revert //...
p4 revert -a //...
p4 revert -n //...
Revert to Specific Revision
p4 sync //depot/project/file.txt#3
p4 sync //depot/project/file.txt#head
p4 edit file.txt
p4 sync -f //depot/project/file.txt#3
p4 resolve -ay file.txt
Submit Operations
Submitting Changes
p4 submit
p4 submit -c 12345
p4 submit -d "Fix player movement bug"
p4 submit file.txt
p4 submit -r -c 12345
Pre-Submit Checks
p4 opened -c default
p4 sync
p4 resolve
p4 diff -se //...
p4 change -o 12345
Status Commands
Workspace Status
p4 opened
p4 sync -n //...
p4 status
p4 reconcile //...
Depot Status
p4 files //depot/project/...
p4 files //depot/project/....cs
p4 fstat //depot/project/file.txt
p4 fstat -Ol //depot/project/file.txt
Reconcile Operations
Finding Untracked Changes
p4 reconcile //...
p4 reconcile -n //...
p4 reconcile -e //...
p4 reconcile -a //...
p4 reconcile -d //...
p4 reconcile -c 12345 //...
Common Workflows
Daily Sync Workflow
p4 opened
p4 sync
p4 resolve
Edit-Submit Workflow
p4 edit file.txt
p4 diff file.txt
p4 submit -d "Description of changes"
Add New Files Workflow
p4 add newfile.txt
p4 opened
p4 submit -d "Add new feature files"
Best Practices
- Always sync before editing - Avoid conflicts
- Use descriptive changelist descriptions - Help others understand
- Submit related changes together - Atomic commits
- Revert unchanged files with
p4 revert -a
- Check
p4 opened before leaving for the day
- Use
p4 reconcile to catch local changes
- Preview with
-n before destructive operations
- Use exclusive locks for binary files
- Don't submit broken code - Test first
- Keep changelists small - Easier to review/revert
Troubleshooting
| Issue | Solution |
|---|
| "File not on client" | Run p4 sync first |
| "Can't edit - not synced" | Sync file, then edit |
| "Can't clobber writable file" | Use p4 sync -f or fix permissions |
| "File already open" | Check p4 opened -a for who has it |
| "Out of date" | Sync and resolve before submit |
| "No such file" | Check path, use p4 files to verify |