24

I wonder if there is any way to move a Changelist which was created editing on /main/ to a branch /dev/branch?

I have six such Changelists with a lot of files in them. I shelved all files and would like to move them to the branch to keep working there. I would prefer to do this directly in P4V, if possible.

I'm using P4V 2011.1 with the 2010.2 P4 server.

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
Martin Schulze
  • 2,091
  • 2
  • 22
  • 27
  • Related question: http://stackoverflow.com/questions/300160/can-i-integrate-checked-out-files-into-a-different-branch-on-perforce. – gdw2 Feb 19 '13 at 19:58

5 Answers5

21

Starting with Perforce 2013.1, you can shelve a file in one branch and unshelve it into another, using a branch spec or stream as the mapping.

Here is the documentation which describes the new -b and -S options.

Matt Dillard
  • 14,677
  • 7
  • 51
  • 61
  • Can you bring and example on how to use -b? The documentation only says use -b flag! I've been trying several variations and it does not work, saying unknown branch '/dev/branch' – Shervin Jan 06 '16 at 21:16
  • 2
    Found it. For the record, -b should be given branch mapping from the shelved branch to the branch we want changelist to be unshelved. Here's how to create a mapping: http://www.perforce.com/perforce/doc.current/manuals/p4v/Managing_branch_specifications.html – Shervin Jan 06 '16 at 21:39
  • @Shervin dead link :-( – user234461 Mar 06 '18 at 15:57
  • @user234461 if the link is dead, try searching "perforce create a branch mapping" in google. The first link explains it pretty well: "To create a branch mapping, choose File > New > Branch Mapping…​ and enter the required information. ... ,e.g., //depot/jam_proj/... //depot/jam_r2.0/... " – Shervin Mar 07 '18 at 19:03
  • this works, i have to give an up-vote. shevele file, using p4v to unshelve, then select branch mapping option to select the branch you want to copy – ShawnLee Feb 20 '21 at 07:11
1

I believe that you can right-click on an edited file and choose Rename/Move....

If that does not work, you'll probably have to use the command line and do p4 move -f old_file new_file and move to another branch.

Note: For what it's worth, this works for branches but not streams.

Chance
  • 2,653
  • 2
  • 26
  • 33
  • 1
    Unfortunately, when I try to move a file to the branch with this method I get a "already exists in depot" error. – Martin Schulze Feb 16 '12 at 19:39
  • @MartinSchulze, that's what I was afraid of. On command line this is where the `-f` comes in, but don't know if there's a way to do that in p4v. – Chance Feb 16 '12 at 19:59
0

You can also use "p4 move -f /main/... /dev/branch/..." to accomplish this.

  1. make sure that the only editable files you have in /main/... are the ones you wish to move. Shelve and revert files in any other changelist
  2. command line: "p4 move -f /main/... /dev/branch/..."
  3. the files in the changeset are now on /dev/branch marked as requiring resolve
  4. Resolve each file just as you would an ordinary conflict
0

I haven't tried this myself, but I would imagine this should be possible:

  1. Change your client to a workspace that contains mappings for the destination branch
  2. Select the pending changelist and unshelve it (or call p4 unshelve -s <number> from the command line

From the p4 manual:

A successful unshelve operation places the shelved files on the user's 
workspace with the same open action and pending integration history as 
if it had originated from that user and client.
jhwist
  • 15,201
  • 3
  • 40
  • 47
  • 3
    Unfortunately the shelved files are stored against depot paths, not workspace paths. So even though you switch to a new workspace with a different branch, when you unshelve, P4 tries to check out files against main. – Tim Robinson May 18 '12 at 15:24
  • Is it not possible to specify the branch mapping somehow? – Entalpi Apr 13 '21 at 09:38
-2
  1. submit it on /main/
  2. integrate the changelist to /dev/branch/
  3. rollback or backout the changelist on /main/

This allows you to resolve conflicts if there are any. The disadvantage is the backing out of the changelist on /main/ which is not pretty.

Marko
  • 20,385
  • 13
  • 48
  • 64
  • If you back out the change on main, won't this reverse the integration history? That is to say, you would expect that there be unintegrated changes on the branch that aren't yet in main, but from Perforce's point of view, there are unintegrated changes on the main that aren't yet in the branch. – Daniel Yankowsky Apr 02 '13 at 18:10
  • 1
    I gave a -1 because of the reason above. I have actually tried this and it can lead to unexpected behaviour. When you integrate back to main the changes will not be there. – Ykok Jul 14 '15 at 09:34