1---2name: p4-file-operations3description: File Operations4---56# File Operations78Use the `query_files` and `modify_files` tools to work with files in P4 depots.910## Querying Files1112| Action | Purpose | Key Parameters |13|--------|---------|----------------|14| `content` | Get file content at a revision | `file_path` |15| `history` | Get revision history (filelog) | `file_path`, `max_results` |16| `info` | Get file metadata (type, size, head revision) | `file_path` |17| `metadata` | Get extended file metadata | `file_path` |18| `diff` | Compare file revisions or depot vs workspace | `file_path`, `file2`, `diff2` |19| `annotations` | Get per-line blame/annotation | `file_path` |20| `search` | Search for files by name pattern (wildcard) | `file_path`, `pattern`, `max_results` |21| `grep` | Search for files by content pattern | `file_path`, `pattern`, `case_insensitive`, `max_results` |2223## Modifying Files2425| Action | Purpose | Key Parameters |26|--------|---------|----------------|27| `add` | Mark a new file for add | `file_paths`, `changelist` |28| `edit` | Open an existing file for edit | `file_paths`, `changelist` |29| `delete` | Mark a file for delete (requires approval) | `file_paths`, `changelist` |30| `move` | Move/rename a file | `source_paths`, `target_paths`, `changelist` |31| `revert` | Revert opened files to depot version | `file_paths` |32| `reconcile` | Reconcile workspace with depot (detect offline edits) | `file_paths` |33| `resolve` | Resolve file conflicts after integration | `file_paths`, `mode` |34| `sync` | Sync files from depot to workspace | `file_paths`, `force` |3536## Common Workflows3738### Edit and submit a file39401. `modify_changelists` → `create` a pending changelist412. `modify_files` → `edit` to open the file in the changelist423. Make your changes locally434. `modify_changelists` → `submit` to commit4445### Add new files46471. `modify_changelists` → `create` a pending changelist482. Create the file(s) locally in your workspace493. `modify_files` → `add` to mark them for add504. `modify_changelists` → `submit`5152### Investigate file history53541. `query_files` → `history` to see revision log552. `query_files` → `diff` to compare specific revisions563. `query_files` → `annotations` to see per-line authorship574. `query_files` → `content` to read a specific revision5859### Find files by name or content60611. `query_files` → `search` with a wildcard pattern (e.g., `*.py`) to find files by name622. `query_files` → `grep` with a text pattern to find files containing specific content633. Use `query_files` → `content` to read files found from search results6465### Sync and resolve conflicts66671. `modify_files` → `sync` to get latest from depot682. If conflicts exist, `modify_files` → `resolve` to handle them693. `modify_changelists` → `submit` when resolved7071### Reconcile offline edits72731. Make changes outside of P4 (e.g., IDE edits without opening files first)742. `modify_files` → `reconcile` to detect and open changed files7576## Best Practices7778- Always open files for `edit` before modifying them so changes are tracked.79- Use `reconcile` if you forgot to open files first — it detects offline edits, adds, and deletes.80- Use `diff` to verify changes before submitting.81- Use `annotations` to understand who last changed each line (useful for debugging).82- Specify `changelist` when opening files to keep changes organized.83- When moving files, both source and target must be in the same changelist.