Can I integrate checked out files into a different branch on perforce
Asked Answered
I

6

10

We were working on a design, and for that we created the skeleton of the classes in our main branch. Now, we are starting to code, and for that we got a new branch. So, it would be nice if I can move all the new files in the main branch into the new branch. However, I cannot check them in yet. So, is it possible to integrate the checked out changelist? Thanks.

Inflectional answered 18/11, 2008 at 21:12 Comment(0)
G
10

The Perforce support web site explains how to do this: Perforce Knowledge Base: Branching work in progress. It would be nicer if it was a single step that didn't require running eight different commands.

Gleich answered 19/11, 2008 at 1:58 Comment(3)
This is the right answer - done it loads myself and is very easy.Aenneea
It amazes me that git gets flack for being "hard to use" when the p4 equivalent of "git rebase" is some 15 commands.Josiah
That said, future searchers should look at the -b and -S options for p4 shelve in p4 2013+ that allow you to rebase a shelved changelist against another branch.Josiah
C
6

Since release 2013.1, the way to branch work in progress is to shelve the work and unshelve it on the branch. In detail:

  1. Shelve your outstanding changes:

    $ p4 shelve ...
    Change 182535 created with 10 open file(s).
    Shelving files for change 182535.
    edit //info.ravenbrook.com/project/mps/master/code/arenavm.c#26
    # etc.
    
  2. Unshelve them on the branch (using the -b option, which maps the file name through a branch specification):

    $ p4 unshelve -b mps/branch/2013-06-05/diag -s 182535
    ... //info.ravenbrook.com/project/mps/branch/2013-06-05/diag/code/arenavm.c - must resolve //info.ravenbrook.com/project/mps/master/code/arenavm.c@=182535 before submitting
    # etc.
    
  3. Resolve any merges resulting from the unshelve, using p4 resolve -as to quickly do the "safe" ones, and then doing the rest with p4 resolve as usual.

    $ p4 resolve -as
    //gdr-peewit/info.ravenbrook.com/project/mps/branch/2013-06-05/diag/code/arenavm.c - copy from //info.ravenbrook.com/project/mps/master/code/arenavm.c
    # etc.
    $ p4 resolve
    No file(s) to resolve.
    

(The example output is from a real use case I ran just now.)

Cadence answered 5/6, 2013 at 13:7 Comment(0)
M
0

I never found a way to do that within perforce, but you can at least partially automate it.

Usually when I had to do something like that I'd check out the files in the branch I want to move things to, then use WinMerge to diff the branches and copy the changes over. Once that's done you can revert the changes in the original branch and check them in in the new branch.

It's not the best solution (no automatic checkout/add/delete of files on the new branch), but was the fastest method I came up with.

Mcmillin answered 18/11, 2008 at 21:38 Comment(0)
P
0

Not really.

You can of course simply open the files for edit in the new branch, and manually copy the changed files from the workspace of your main branch to the new branch's workspace. This is probably the easiest way if it just a few files.

Here are a few scripts that can be handy if a larger number of files are involved. E.g., with the P4Shelf script you can create an archive of all your changed files, and later automatically open them in any branch with the changes restored.

Also, check out some other nifty scripts for Perforce by Jim Tilander.

Pushkin answered 18/11, 2008 at 21:52 Comment(0)
D
0

To rephrase Gareth Rees' answer above in simple terms,

p4 unshelve -b target_branchspec -s changelist

:)

Deplume answered 12/6, 2014 at 6:54 Comment(0)
I
-1

The easy answer is - no you can't. A quick perusal of the Perforce docs didn't come up with a ready cite for this, unfortunately, but in my experience any attempt to pull the rug out from under the Perforce server will result in your changes being lost which will leave you an unhappy camper.

Make a back up, create a new work area on the new branch, and re-apply your changes, perhaps using the diff/merge strategy outlined in Herms answer.

Inspired answered 18/11, 2008 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.