Suppose i had a main branch -
//project/main/...
and than i created new branch from main -
//project/1.0/...
and then again i created branch from 1.0 -
//project/2.0/...
Now, if someone wants to know from which branch branch 2.0 created, how can user identify?
Select a file and use the Perforce Revision Graph to see the relationships between branches for a particular file.
Perforce does not have Branch as a first-class object, so you have to look at the branch history of individual files.
You could also dump all the branch definitions and try to link the heads and tails of the different branch specifications with a perl script and a graphing tool like GraphViz.
From the command line, doing p4 filelog -i //somefile will show the branch history. It's the command line equivalent of the answer xt1 gave.
Related
If I use the perforce command filelog it appears to show only the history for the current branch. Is there a way to see the history for all the branches?
EDIT:
the file name looks something like:
//depot/v2/top/foo.c
//depot/v1/top/foo.c
I want to see the history for v1 & v2. Is that a branch?
If you use the -i or -h flags, the history will switch to another branch at branch or copy points respectively, but it will still be linear (just a more curvy line).
If you want a full graph, the best bet is the Revision Graph graphical tool:
https://www.perforce.com/video-tutorials/using-revision-graph
I'm a software engineer that uses git professionally but haven't tried using perforce until today. I searched about branch in perforce but I noticed that most of the informations that I found were all made by just using the branch in GUI then it creates a new folder (ie. /depot/MAIN/ to /depot/DEV/)
Is this how it works? What's the standards in naming the branches? Is it all caps?
Thanks
Branch names do not have to be in upper case only.
To create a new branch you can use the 'p4 integrate' command.
You can also use 'p4 copy' or 'p4 populate', depending on whether you want to exactly copy the source, or do the branch and submit in one action.
More information about branching is located here:
https://www.perforce.com/perforce//manuals/p4guide/chapter.codelines.html
If you're used to git branches you might like Perforce streams and the p4 switch command, which works a lot like git branch. For example:
p4 switch -c dev
stashes your current work, creates a new branch called dev based on your current branch, and switches to it. To bring your current work into the new branch, add the -r flag.
At its core streams really use the same concepts as "classic" (unmanaged) inter-file branching, and there are things you can do with Perforce's branching model that you can't with git's, but if you want something that feels more or less like git the switch command abstracts away a lot of the commands you'd have to learn otherwise.
Let's say I have a file //depot/Project/com/company/project/SomeClass.java that is labeled with name "version-1.0.0". Suddenly I need to revert back to that label to create a bugfix release. I update to it and then make changes to the SomeClass.java.
Now this is the part I don't understand. How do I submit the fixed SomeClass.java to Perforce without overwriting any newer revision of the source tree? With Mercurial or Git I would have a branch that has the fixed source and I would just create the bugfix build from there. But now I have no idea where I should put the fixed file.
You've got essentially the same choices in Perforce as you do in those other systems, although the terminology is a bit different.
The simple solution is to make your change to SomeClass.java, and then make a new label, called "version-1.0.1", which tags the new version of SomeClass.java rather than the old one, but otherwise is identical to the version-1.0.1 label:
p4 sync //...#version-1.0.0
p4 edit SomeClass.java
p4 submit -d Fixed_that_nasty_bug
p4 label version-1.0.1
p4 labelsync -l version-1.0.1
Alternately, you can also make a branch in Perforce, and you can use your label as the basis for making that branch.
So you could do something like:
p4 integrate //depot/Project/...#version-1.0.0 //depot/rel-1.0.1/Project/...
Then you can make your change to //depot/rel-1.0.1/Project/.../SomeClass.java, and submit it back to the rel-1.0.1 branch.
If this is your first time thinking about things like development branches, release branches, etc., can I suggest having a read of http://www.perforce.com/perforce/conferences/us/2005/presentations/Wingerd.pdf or picking up a copy of Laura Wingerd's Practical Perforce and reading the chapter on "the mainline model"?
I would like to know how to rename a branch specification (aka, a "branch mapping") in perforce. The P4V client does not allow you to edit the branch spec name.
Is it safe to just add another branch specification, copy the settings and remove the old one?
Perforce does not provide a mechanism to rename a branch specification. Perhaps they fear you may inadvertently break some scripts if you go and rename one?
Yes, it is safe to create a new one, copy the settings from the old and delete it (provided nothing is relying on a branch specification with that old name, of course).
Lack of branch spec renaming extends to all specs (users, groups, clients, labels, jobs, etc.). This is where the command line can come in handy:
p4 branch -o OLDBRANCH | sed -e "s,OLDBRANCH,NEWBRANCH," | p4 branch -i && p4 branch -d OLDBRANCH
Check this link:
http://kb.perforce.com/article/24/renaming-depot-directories
The procedure depends on your server version. For example in the 2009+ servers you use pedit and pmove to rename and keep your file history.
Yes. But you need to do an p4 integrate to get the files over. That is what p4v "copy or rename" does. Use the rename option, that also deletes the old files.
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.
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.
Since release 2013.1, the way to branch work in progress is to shelve the work and unshelve it on the branch. In detail:
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.
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.
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.