5

We are migrating from clearcase to perforce and I have question on branching.

In clearcase once I branch (say my_branch) out I can keep committing incremental changes to a file (say xyz.cpp) without being concerned about the main.

element * CHECKEDOUT
element * .../my_branch/LATEST
element * /main/LATEST -mkbranch my_branch

I can keep checking out and checking in xyz.cpp as many times as I want into my_branch. Suppose I made 23 checkins and I feel the 21st checkin is the one that needs to go into the main, I can get the 21st checkin using ct get and merge it to main.

I can do this for any number of files (say xyz2.cpp, xyz3.cpp ...) in this branch in clearcase. I am not sure how to do this in perforce.

How do I replicate this process in perforce? I see p4 submit but it goes into main. Basically I want to keep saving the incremental changes and also retrieve them as needed for any number of files before merging them to main.

Cratylus
  • 52,998
  • 69
  • 209
  • 339
Anand
  • 1,122
  • 3
  • 20
  • 33

2 Answers2

5

You can use much the same process but of course the mechanics are different.

Step 1: Make your new branch

Let's say that you have a main branch in Perforce located at //depot/project/main. (That path is in Perforce depot syntax. I can add a link to the relevant docs if you need it.)

I'll define a branch map to capture the information about how the main branch and my new branch relate to one another.

p4 branch my_branch

In the branch map I will add this view:

//depot/project/main/... //depot/project/my_branch/...

Now I will create the branch:

p4 populate -b my_branch

Step 2: Use the new branch

I'll create a workspace that contains both branches. I won't go into all the details but I need a workspace view that looks something like this:

//depot/project/main/... //my_ws/main/...

//depot/project/my_branch/... //my_ws/my_branch/...

Now I'll populate the workspace:

p4 sync

Note that I'll have a copy of both branches in my workspace. Now I'll check out and make changes on my_branch:

p4 edit my_branch/foo.c

p4 submit -d "my_branch changes

I can make as many changes on my_branch as I need.

Step 3: merge to main

Ok, now I'm ready to merge my_branch to main. If I want to merge everything I run:

p4 integ -r -b my_branch

If I want to just merge a single file:

p4 integ -r -b my_branch //depot/project/main/foo.c

Note that I specify the target file.

If I want to just merge a specific revision of a single file:

p4 integ -r -b my_branch //depot/project/main/foo.c#21

randy-wandisco
  • 3,649
  • 16
  • 11
  • Great! +1. Those were the missing commands around branch missing in my answer. – VonC Nov 07 '12 at 22:33
  • @p4-randall Thank you. Your answer was very clear and provides a simple model to visualize branching and merging in perforce. – Anand Nov 07 '12 at 22:43
  • @p4-randall Typing in `p4 populate -b my_branch` results in `Unknown command. Try 'p4 help' for info.` Any command to work around this? – Anand Nov 07 '12 at 22:58
  • p4 populate is a relatively new command and might not be available in your version. If not then substitute p4 integ -b my_branch followed by p4 submit. – randy-wandisco Nov 08 '12 at 01:31
  • @p4-randall Thank you. In step 2 you mention ``I'll create a workspace that contains both branches''. Can you please provide a link which explains the need for this. I thought it should sufficient to map the `my_branch` to the `my_ws`. Why do we need to map `main` to `my_ws`? – Anand Nov 08 '12 at 19:05
1

The closest from cleartool get would be p4 sync

 p4 sync file.c#4

Copy the fourth revision of file.c to the client workspace.
If the file is already open in the client workspace, or if the latest revision of the file exists in the client workspace, it is not copied.

After that p4 submit remains an obvious choice, but all files in the changelist are submitted to the depot, and files open for edit, add, and branch are closed.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you. But how do I `submit` the changes to `file.c` locally to a branch instead of submitting to `main`? – Anand Nov 07 '12 at 21:02