Ora

How Do I Get My Revision History in P4?

Published in Perforce Revision History 5 mins read

You can retrieve your revision history in Perforce (P4) using both the P4V graphical user interface (GUI) and the P4 command-line interface (CLI) to view changes made to files, folders, or entire changelists. Understanding how to access this history is crucial for tracking changes, debugging, and collaborating effectively.

Understanding Perforce Revision History

In Perforce, every change submitted to the depot is assigned a unique changelist number, and each file within that changelist receives a new revision number. Revision history allows you to:

  • See who made changes and when.
  • View specific versions of files.
  • Compare different revisions.
  • Revert to previous states.

Retrieving Revision History Using P4V (Graphical User Interface)

P4V offers an intuitive way to browse and interact with your Perforce revision history.

For Specific Files or Folders

To view the history of a particular file or folder:

  1. Navigate: In the P4V Depot or Workspace pane, locate the desired file or folder.
  2. Access History: Right-click the file or folder and select History.
  3. Explore Revisions: A new pane or tab will open, displaying a list of all changelists that affected the selected item.
    • Each entry shows the changelist number, user, date, and description.
    • You can double-click a revision to view details or right-click to access options like:
      • Diff Against Workspace File: Compare the selected revision with your current local file.
      • Diff Against Previous Revision: Compare the selected revision with the one immediately preceding it.
      • Get This Revision: Sync your workspace to that specific file revision.

For Files within a Changelist

When you need to interact with files associated with a specific submitted changelist:

  1. Locate Changelist: In the P4V Submitted Changelists pane, find the changelist you're interested in.
  2. Get Revisions: To get the revision of all files in a specific changelist, right-click the desired changelist and select Get Revisions for Files in Changelist <Changelist_ID>. If you need to retrieve files from multiple selected changelists, right-click the selection and choose Get Revisions for Files in Changelists. This action will sync your workspace copies of those files to their state at the time of that particular changelist's submission.
  3. View Files: You can also double-click a changelist to open its details, showing all files involved and their respective revisions within that submission.

For Entire Branches or Labels

To understand changes across a larger scope, such as a branch or a specific labeled release:

  1. Browse Labels: Navigate to the "Labels" tab or pane in P4V.
  2. View Files: Right-click a specific label and choose "View Files" to see all files tagged by that label. From there, you can view the history of individual files as described above.

Retrieving Revision History Using P4 CLI (Command-Line Interface)

The P4 CLI provides powerful and scriptable ways to access revision history.

Viewing File Revision History (p4 filelog)

The p4 filelog command is your primary tool for examining the history of files.

  • Basic Syntax:
    p4 filelog <filepath>

    Example: p4 filelog //depot/projectA/src/main.cpp

  • Common Options:
    • -l: Include the full description for each changelist.
    • -m <max_revisions>: Limit the number of revisions displayed.
    • -t: Show file types (e.g., text, binary).
    • @<changelist_id> or #<revision_number>: Specify a range for history.
      Example: p4 filelog -l //depot/projectA/src/main.cpp@12345 (show history up to changelist 12345)

Viewing Changelist History (p4 changes and p4 describe)

To see a list of submitted changelists or details about a specific one:

  1. List Changelists (p4 changes):
    p4 changes <filepath_or_depot_path>

    This command lists submitted changelists, showing the changelist number, user, date, and description.
    Example: p4 changes //depot/projectA/... (lists all changes in projectA)

    • Useful Options:
      • -u <user>: Filter by user.
      • -m <max_changelists>: Limit the number of changelists shown.
      • -s submitted: Show only submitted changelists (default).
  2. Describe a Changelist (p4 describe):
    p4 describe <changelist_id>

    This command provides detailed information about a specific changelist, including the description, files affected, and the exact operations performed (add, edit, delete).
    Example: p4 describe 12345

Syncing to a Specific Revision or Changelist

You can update your workspace files to a particular point in history:

  • Sync by Revision Number:
    p4 sync <filepath>#<revision_number>

    Example: p4 sync //depot/projectA/src/main.cpp#5 (gets revision 5 of main.cpp)

  • Sync by Changelist:
    p4 sync <filepath>@<changelist_id>

    Example: p4 sync //depot/projectA/...@12345 (syncs all files in projectA to their state at changelist 12345)

Practical Tips for Navigating History

  • Diff Tools: Use built-in or external diff tools (accessible from P4V or via p4 diff) to visually compare different file revisions.
  • Revision Specifiers: Understand that #head refers to the latest revision, #have refers to the revision currently in your workspace, and @<changelist_id> refers to the state of files at that changelist.
  • Filtering: P4V offers powerful filtering options for changelists by user, date range, file path, and more.

Summary of Revision History Commands/Actions

Action P4V (GUI) P4 CLI (Command Line) Description
View File History Right-click file/folder > History p4 filelog <filepath> See all changes for a specific file or folder.
View Changelist Details Double-click changelist in "Submitted Changelists" p4 describe <changelist_id> Get full details of a specific submitted changelist.
List Submitted Changelists "Submitted Changelists" pane p4 changes <filepath> View a list of recent submitted changelists.
Get Files from a Changelist Right-click changelist > Get Revisions for Files p4 sync <filepath>@<changelist_id> Sync your workspace files to their state at a specific changelist.
Compare File Revisions Right-click revision > Diff p4 diff <filepath>#<rev1> <filepath>#<rev2> Compare two different revisions of a file.

For more detailed information on Perforce commands, you can refer to the official Perforce documentation, such as the P4 Command Reference or the P4V User Guide.