How to unshelve a shelved changelist to another branch prior to Perforce 2013?
Categories:
Unshelving Perforce Changelists to Another Branch (Pre-2013)

Learn the manual process of unshelving a Perforce changelist to a different branch, a common task before the introduction of the 'p4 unshelve -s' command in Perforce 2013. This guide covers the steps for older Perforce versions.
Before Perforce 2013.1, the p4 unshelve -s
command, which directly allows unshelving a changelist from one branch to another, did not exist. This meant that developers working with older Perforce servers needed a manual workaround to achieve the same result. This article details the step-by-step process for unshelving a shelved changelist to a different target branch using a client workspace and a temporary branch, ensuring your changes are correctly applied.
Understanding the Challenge
In modern Perforce, unshelving to a different branch is straightforward. You simply switch to your target branch, and use p4 unshelve -s <shelved_changelist_number>
. However, in older versions, p4 unshelve
only operated on the current client workspace's branch. To move changes between branches, you had to manually integrate the shelved changes into your target branch. This typically involved creating a temporary branch or carefully merging the shelved files.
flowchart TD A[Shelved Changelist on Source Branch] --> B{Switch Client to Target Branch} B --> C[Create Temporary Branch/Files] C --> D[Integrate Shelved Files Manually] D --> E[Resolve Conflicts (if any)] E --> F[Submit Changes to Target Branch] F --> G[Clean Up Temporary Files/Branch] G --> H[Done]
Manual Unshelve Workflow (Pre-Perforce 2013)
Prerequisites
Before you begin, ensure you have:
- Access to the Perforce server with appropriate permissions.
- A Perforce client workspace configured.
- The changelist number of the shelved changes you wish to unshelve.
- Knowledge of your source and target branch paths.
Step-by-Step Manual Unshelve Process
This process involves creating a temporary client workspace or modifying your existing one to facilitate the transfer of changes. The core idea is to get the shelved files into your target branch's workspace, then integrate and submit them.
1. Step 1: Create a Temporary Client Workspace (or adjust existing)
It's often safest to create a new client workspace specifically for this operation. This prevents accidental modifications to your primary workspace. Map this new workspace to your target branch. For example, if your target branch is //depot/main/...
, your client view should reflect this.
2. Step 2: Populate the Temporary Workspace with Target Branch Files
Sync your new client workspace to the head revision of your target branch. This ensures you have the latest files from the branch you intend to unshelve into.
3. Step 3: Unshelve the Changelist into a Temporary Location
Now, you need to get the shelved files from the source changelist into your temporary workspace. Since p4 unshelve
only works on the current branch, you'll unshelve it into a temporary location within your current (target branch) workspace. This will create pending changes in your temporary workspace.
4. Step 4: Integrate the Unshelved Files
After unshelving, the files are now in your client workspace. You need to integrate these files into your target branch. This is where the manual merging happens. You'll use p4 integrate
to merge the changes from the temporary files (which originated from the shelved changelist) into the actual target branch files.
5. Step 5: Resolve Conflicts
If there are any conflicts during the integration, you will need to resolve them manually using p4 resolve
. This is a critical step to ensure the integrity of your target branch.
6. Step 6: Submit the Changes
Once all conflicts are resolved and you're satisfied with the merged files, submit the pending changelist to your target branch. This officially applies the shelved changes to the new branch.
7. Step 7: Clean Up
After successful submission, you can delete the temporary client workspace and any temporary files created during this process.
p4 diff
and p4 diff -sr
before submitting to ensure that only the intended changes are being submitted. This is especially important in manual integration scenarios.Example Commands
Let's assume:
- Shelved changelist ID:
12345
- Source branch path:
//depot/dev/featureA/...
- Target branch path:
//depot/main/...
- Your client workspace root:
/p4/client_root
# 1. Create a new client spec for the target branch (or modify existing)
p4 client my_temp_client
# In the client spec, set the View to map to the target branch:
# View:
# //depot/main/... //my_temp_client/...
# 2. Switch to the new client and sync
p4 client my_temp_client
p4 sync
# 3. Unshelve the changelist into the current workspace
# This will create pending changes in your current client (my_temp_client)
p4 unshelve -c default 12345
# 4. Integrate the unshelved files (now pending in your workspace)
# This step is conceptual. The files are already in your workspace
# as pending changes. You just need to ensure they are correct.
# If the shelved changelist contained new files, they will be 'add'ed.
# If it contained modifications, they will be 'edit'ed.
# If it contained deletes, they will be 'delete'd.
# 5. Resolve any conflicts
p4 resolve -am
# 6. Submit the changes
p4 submit -d "Unshelved changelist 12345 from //depot/dev/featureA to //depot/main"
# 7. Clean up (delete the temporary client)
p4 client -d my_temp_client
Example Perforce commands for manual unshelving
While this method is more cumbersome than the modern p4 unshelve -s
command, it was the necessary approach for Perforce users prior to the 2013.1 release. Understanding this manual process provides insight into Perforce's evolution and offers a solution for those still working with legacy systems.