Perforce, can submitted changes be shelved? - perforce

P4 version... Proxy version: P4P/LINUX26X86_64/2013.2/821990 (2014/04/08)
Let's say I made a bunch of changes and some adds, all in the default CL, then "p4 submit"ted them . Let's say the CL generated was 12345. Then I realized that I forgot a file, made that change, submitted it and that CL is 12346. After all this is done, someone wants me to duplicate that work on another branch. Would have been nice if I shelved the changes that are in 12345 and 12346 but I didn't.
Is there a way to create a new changelist that = 12345 + 12346, which is something that I can shelve and then bring into that other branch ?
Thanks!

Technically you can do this with shelves and a lot of manual work, but what you're describing is what p4 integrate is for.
p4 integ source_branch/...#12345,12346 target_branch/...
p4 resolve -am
The change to target_branch (which consists of everything you did in changes 12345 thru 12346 on source_branch) is now pending in your workspace -- you can either p4 shelve it or just p4 submit it directly.

Related

Perforce Changelist and shelve command

I am very new to Perforce and just started using it.
After syncing my code using $p4 sync command i started editing a few files.
$p4 edit file1
$p4 edit file2
$p4 edit file3
These files were getting added to my default changelist. For collaborating with my team i wanted to create a changelist. For creating a changelist i ran $p4 change and removed "file1" from the changelist description. Now when i run $p4 opened. It gives an output similar to this.
//depot/... /file1 edit default change (text)
//depot/... /file2 edit default 111 (text+k)
//depot/... /file3 edit default 111 (text+k)
Now i have the following questions in my mind:
Which changelist am i currently working on is it default or 111 ??
what is the meaning of (test + k)?
When i make changes to file2 and file3 it is getting synced to changelist 111 and when i make changes to file1 it gets synced to default changelist . I am highly confused how is this happening ?
Also one more thing i am confused about is if do $p4 shelve will my changes disappear and will be reapplied only when i run unshelve command for the changelist created ?? Is this similar to git stash and git stash apply ?
It will be great if someone can answer these questions in detail. Any tutorial suggestions for Perforce will also be of great help.
Thanks in advance.
My recommendation for a Perforce tutorial is the Perforce User's Guide. Here's the section on changelists:
https://www.perforce.com/perforce/r15.1/manuals/intro/chapter.working_in_perforce.html#working_in_perforce.working_with_files.changelists
Which changelist am i currently working on is it default or 111 ??
Both! Both of these are pending changelists in your workspace.
what is the meaning of (text+k)?
The thing in parentheses is the "filetype". +k is a "filetype modifier" meaning that keywords (special words like $Id$ and $Revision$ and $Author$ in this file will be automatically expanded to appropriate values when you submit.
When i make changes to file2 and file3 it is getting synced to changelist 111 and when i make changes to file1 it gets synced to default changelist . I am highly confused how is this happening ?
Nothing is getting "synced" anywhere yet -- the pending changelists are just containers that reference the different files. When you shelve or submit, then the files associated with those changelists will get sent to the server and will be accessible by other clients. Since shelve and submit are changelist-level operations, only the files in those changelists are affected -- that's the point of having different pending changelists. You have all of the pending files in your workspace, but you can split up which ones get sent to the server at which times (it's a little like pushing different branches in git, but not -- you can do this on every operation in Perforce even when you aren't branching because each file is versioned individually rather than having the entire tree versioned as one atomic blob).
Also one more thing i am confused about is if do $p4 shelve will my changes disappear and will be reapplied only when i run unshelve command for the changelist created ?? Is this similar to git stash and git stash apply ?
No, p4 shelve only syncs the shelved change on the server with the local files in your workspace -- it doesn't in itself change your workspace. The equivalent of "stashing" would be to p4 shelve and then to p4 revert to wipe out the workspace changes. shelve on its own is a little more like doing a git push to a branch -- you keep your local copy but now it's also on the server (but not part of the "master" history). (It's not exactly the same though -- to be honest if you're brand new to Perforce I'd stick to regular old "submit" in a regular old branch since that's the basic workflow. Sharing work via shelves requires a lot more manual work since each shelf is like its own little mini-branch with no versioning.)

Perforce: Propagate changes from a file to another

How can I take changes from a file that I have in my depot and apply it to a file in my current workspace.
Consider the following scenario.
I have a branch A where I have submitted some changes to files a1, a2 and a3. The change number associated for this submission is 123.
Now I am in another branch B that I am currently working on. I have to take the changes of file A/a1 that I made as a part of change number 123 and apply it to B/a1.
I tried using perforce-integrate, but I am not able to make it work.
To propagate all of change 123 from A to B:
p4 integ A/...#123,123 B/...
p4 resolve -am
p4 resolve # (if needed)
p4 submit
To propagate ONLY a1#123,123:
p4 integ A/a1#123,123 B/a1
p4 resolve -am
p4 resolve # (if needed)
p4 submit
If any part of this does not work, an error message will be displayed indicating what you need to correct in order to make it work.

Reverting multiple checkins in perforce

I have made several checkins using perforce. I have no realized that all of them are unnecessary. I would like to revert all the changes for the last x revisions in the working directory, update the version number, and check in.
I am familiar with Mercurial. The way that I would it for that would be:
$ hg revert -r last_good_changeset .
$ edit version-number.txt
$ hg ci
Is there a way to do something similar in perforce?
In Perforce, a revert refers to restoring a file to the state it was in before it was checked out. What you're looking to do is back out a submitted changelist. This Perforce KB article has a few methods to do what you're trying to do, depending on your particular circumstance.
For example, if you have revisions #1 - #6 of a particular file, and you want to roll back to revision #3, you'd do this:
p4 sync myfilename#3
p4 edit myfilename
p4 sync myfilename
You're telling Perforce to get revision #3 from the depot, check it out for edit, then try to sync it back up to #head (the latest version in the depot). Since the file is checked out from an earlier revision, Perforce schedules a resolve so you need to tell it what you want to do with the file: accept the version in the depot, accept your local changes, or try to merge the two. You'll want to tell Perforce to accept the local version (or in Perforce parlance "yours"):
p4 resolve -ay myfilename
Now that it's resolved, you can submit it with:
p4 submit
If you have a series of files you want to do this with (for example, you've edited a bunch of files in a given directory and have checked them all in together several times, and you want to back out all of those), you can use changelist syntax as well. For example, if you want to roll everything back in a given directory to changelist 123, you can do this:
p4 sync //depot/some/path/*#123
p4 edit //depot/some/path/*
p4 sync //depot/some/path/*
p4 resolve -ay //depot/some/path/*
p4 submit
This will work for any revision modifier (see p4 help revisions for alternate methods of specifying the version you want).
The rollback function is specifically designed to do this. It goes back to a certain date/time or change list # and reverts all changes in the window you give it.
Simply right click on the file in question (P4V obviously) and select rollback. It will bring up this box. Not sure how to execute from command line...Ill see if I can figure it out and add that info.

Add a file to shelved perforce changelist from another workspace

I have a changelist #1234 which I shelved from destop1. It has 5 files but I want to add another file to it say 6.c. The problem is when I do p4 edit -c 1234 6.c from desktop2, p4 errors out something like change 1234 belongs desktop1. desktop1 and desktop2 are different workspaces under same user.
How to release changelist 1234 and let me allow to do this?
One approach is to create a second changelist: using the desktop2 workspace, do 'p4 unshelve -s 1234' which will unshelve all the files into your second workspace in the default changelist. Then do 'p4 edit 6.c' on desktop2 and make your changes. Then do 'p4 shelve' and create a new shelved changelist (it will have a different changelist number).
The advantage of this approach is that you still have the first changelist in case you decide that you preferred the first version.
You can test the one changelist, then test the other, and decide which one you want to keep.
When you're all ready, you can submit the changelist you decided that you like, and delete the changelist that you decided not to keep.

Perforce merge changelist

I am facing an issue of merging due to bad scm practices followed. I gave a build off of a perforce branch when the latest changelist # was, lets say, 1000. Now after the dev team has submitted many more changelists the latest changelist # is 1050. Issue is that smoke test on the build failed and now I fixed it and submitted a changelist # 1051.
My question is there a way to somehow merge the change made in 1051 into 1000. Or in other words create a build with all the changes upto changelist # 1000 and including only changelist # 1051 as well.
I hope I was able to explain the issue in a way that makes sense.
P.S: I know the concept of Main, Release, and Dev branches. Somehow now I am in this mess of giving a build off of the dev branch and looking for a solution.
One way is to create another branch, as in:
p4 integ //depot/build/branch/...#1000 //depot/bugfix/branch/...
p4 submit
p4 integ //depot/build/branch/...#=1051 //depot/bugfix/branch/...
p4 resolve
p4 submit
Now build //depot/bugfix/branch and give that to your test team.
Try
p4 sync //depot/branchname/... #1000
p4 sync //depot/branchname/... #1051,#1051
This tells perforce, sync the workspace to changelist 1000. Then 2 says sync all files from changelist 1051 to 1051, basically it means only sync the changes that are in changelist 1051. You can use p4v as well
Right click on //depot/branchname and Get Revision, then type in 1000 as the changelist.
In the submitted tab on the right, right click on 1051, Get Revision. Click tha add button to add //depot/branchname, type in 1051 as the changelist, and then check the "only get files listed in this changelist" checkbox.

Resources