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

▼魔方 西西 提交于 2019-11-30 18:40:01
bk1e

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.

Gareth Rees

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.)

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.

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.

To rephrase Gareth Rees' answer above in simple terms,

p4 unshelve -b target_branchspec -s changelist

:)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!