8

Is there a good way in Perforce to move unsubmitted changes to a different stream before submitting them (equivalent of git stash, git checkout otherbranch, git stash pop)?

I currently have the files checked out locally (non-exclusively) and edited. I've tried shelving them and then trying to unshelve them into the target stream, but I get "file(s) not in client view". When I view the changelist (shelved or not), the files all have paths that include the original stream.

My target stream is one I just created, parented off the original stream. I'm using P4V. The version of Perforce Visual Components I have installed is 123.57.9578, and when I run p4 from the command line, it says "Server 2012.2/551823". I can add more info if necessary.

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
entheh
  • 938
  • 1
  • 9
  • 17

5 Answers5

6

You can use the p4 unshelve command to remap the shelved files in a changelist to another stream using the -S option. Ex:

p4 unshelve -s <changlist#-with-shelved-files> -S //depot/streamname

Not sure if this is only available in a certain version or above or not. However, we were unable to find a way to do it through P4V.

az2tonez
  • 86
  • 7
4

The other answers here are correct, but they don't warn you that you can't just shelve from any stream and unshelve on any unrelated stream. In particular, the original poster asked about the error message "file(s) not in client view" which is the error message that P4V displays when you haven't selected the proper mapping.

Here's the trick to finding the proper mapping: Your unshelve stream must have a direct parent/child relationship with the shelved stream, and you must select the stream spec that describes that relationship in the "Map unshelved files using stream..." part of the dialog. This means it may take multiple hops to get from the original shelved stream to the target stream.

Here's a concrete example: Let's say you have files shelved into Dev-1 that you want to move to Dev-2. These two Dev streams are both direct children of Main. You can't unshelve Dev-1's files directly into Dev-2, first you have to unshelve and temporarily re-shelve into Main, because the Dev stream specs both describe their relationship in terms of Main and not each other.

So, you unshelve Dev-1's files into Main with "Map unshelved files using stream Dev-1" because that spec describes the relationship being traversed. Then, shelve the files into Main, and then switch your workspace to Dev-2. Now, you can unshelve the Main version of the shelved files, with "Map unshelved files using stream Dev-2", because that spec describes the direct relationship from Main to Dev-2.

With multiple hops, you can get to any other connected stream in your network. This is not as easy as git stash and git stash pop, but remember that Git is assuming the filenames don't change between git branches, whereas Perforce allows each hop to arbitrarily change the mapping of files and folders.

emackey
  • 11,818
  • 2
  • 38
  • 58
  • 1
    Thanks for the answer. I can't really comment as I've moved on and no longer use Perforce, but just wanted to say Git handles renamed and moved files very well in my experience in cases like this. Of course Perforce has its own strengths (partial views in particular), but this didn't seem to be one of them! – entheh Jan 29 '16 at 20:34
3

If you're for some reason more comfortable using P4V than command line, the solution az2tonez gave can be done with the GUI, at least in P4V 2014.2.

  1. Shelve your changeset, and make sure you have no other files checked out in the workspace.
  2. In the 'Streams' tab, drag the workspace icon from the current stream to the stream you want to move the changes to, and get the latest changes.
  3. Unshelve the files in the 'Pending' tab. Under options select 'Map unshelved files' and select the stream you want to move the changeset from, and press 'Unshelve'.
  4. Resolve files using source.
  5. Submit your changes, and voilá! Your changes should now be in the other stream.
DuneCat
  • 788
  • 6
  • 17
  • This will change the workspace to the source one when submit the unshelved files. But it does preserve the uncommitted shelved files and committed the change list to the target stream. You need to get latest revision in the target stream's workspace. – zwcloud Nov 01 '19 at 07:42
1

I believe the shelve/unshelve technique requires the 2013.1 server, not the 2012.2 server. You should confirm this with Perforce Technical Support.

Bryan Pendleton
  • 16,128
  • 3
  • 32
  • 56
  • Thanks for the answer. Unfortunately it seems I have to wait till next week before we can confirm this, as our "Perforce king" is currently at - guess what - a Perforce conference :P – entheh Apr 25 '13 at 14:47
  • Shelving works on older versions of perforce. However, you can only unshelve to the same path, which includes the branch root, so you cannot unshelve in another branch. – André Caron May 03 '13 at 15:17
1

I know this is an old thread, but I just recently needed to do this exact thing. While these answers were conceptually useful in understanding what needed to be done, unfortunately using only the information in this thread, I couldn't quite get it to work.

I wanted to add the perforce link I found afterwards that filled in some of the missing details that helped me understand exactly what needed to be done, in hopes it might help someone else looking to do this and landing in this thread.

https://p1community.force.com/Community2/s/article/3651

fnJeff
  • 31
  • 1
  • 7