How to view Shelved P4 Changes? - perforce

One of our team member (located in different region) has shelved changes in P4 with changelist 1234.
Now, if I want to see what files are modified snf what are the changes, how can I do this?
What is the P4 command that I should use to see the changes made by our team member?

p4 describe -S 1234 should to the trick, see the documentation on describe.
To see the file content you would unshelve the files into your workspace (assuming you have a workspace for the same project your colleague is working on).
Create a new (empty) changelist with p4 change (results in e.g. 2345), then use p4 unshelve (docu) to get the modified files to your workspace:
p4 unshelve -s 1234 -c 2345
If you don't want the modified files in your workspace any longer, you can p4 revert -c 2345 them.

Using the GUI, go to Pending and remove all filters except by user, where you will put the other developer's ID. From there you should be able to see her Changelists, including the ones having shelved files. Right click on the Shelved Files icon and select Unshelve. You will have to have a workspace active that includes the files that you are trying to unshelve.

Using UI client, press Ctrl+G. Dialog window is appears. Select Changelist in combobox and input number of changelist.

Let's assume that changelist 123456 is the shelved changelist in question. As a previous answer mentioned, the way to list the files are associated with that changelist is via the p4 describe -s <changelist> command. Like so:
$ p4 describe -s 123456
Change 123456 by john.doe#JohnsBranch on 2013/10/24 15:38:10 *pending*
[Shelving my changes for Jane.]
Fix memory corruption caused by uninitialized pointer.
Affected files ...
... //depot/branches/JohnsBranch/kernel/vm/pageutils.c#1 edit
Once you know the file(s) in question, there are a couple of ways to diff the files without a corresponding workspace. Method #1 is to use p4 print:
$ p4 print -q //depot/branches/JohnsBranch/kernel/vm/pageutils.c#1 > /tmp/old
$ p4 print -q //depot/branches/JohnsBranch/kernel/vm/pageutils.c#=123456 > /tmp/new
$ diff /tmp/old /tmp/new # Or use kdiff3, tkdiff, etc.
...
<diff output here>
The other method is to use p4 diff2:
$ p4 diff2 //depot/branches/JohnsBranch/kernel/vm/pageutils.c#1 //depot/branches/JohnsBranch/kernel/vm/pageutils.c#=123456
...
<diff output here based on Perforce server's diff algorithm>
Both methods can be easily incorporated into the scripting language of choice.

jhwist's solution is good if you want to see the files' diffs.
If you want to see just the shelved files, use p4 describe -sS 1234.
The lower case s restricts the output from including file diffs.

If you wanted to see the actual content of the files, you could use:
p4 print <file>#=<shelved_change>
The #= means to look at the shelved change, where as # means to look at the change.

If you want to see only the list of files inside a ChangeList (whether it's a shelve, pending or submitted CL), without extra data, grep the result:
p4 describe -S 12345 | grep -oP '(?=//).*(?=#)'

In P4V UI, select
Search - > Go To
then choose type of changelist (in your case 'Pending changelist'), enter changelist number and click "OK".

You may try
p4 -ztag describe <changeno>
The description contains a string called '... shelved' if it is shelved.

Related

In perforce, how can I reopen all elements of a CL into the default CL ?

Server version: P4D/LINUX26X86_64/2013.2/938876 (2014/09/23)
Hi:
Let's say I have a pending changelist 123 which has these 2 files...
... //foo/somewhere/abc.txt#100 edit
... //foo/somewherelse/def/txt#67 edit
I want to put both of these in the default CL. I know I can
"p4 reopen -c default //foo/somewhere/abc.txt"
and then
"p4" reopen -c default //foo/somewherelse/def.txt"
But is there a way to specify all the files in CL 123 regardless of the paths (do both reopens with one command)?
My actual situation involves a shelvelist. I want to put the changes in a shelvelist back in the default CL then delete the shelvelist AND the changelist that results after one deletes a shelve. Basically I want to undo the shelve operation. My method of doing this is...
1) delete the shelve
2) p4 describe the changelist
3) p4 reopen -c default each file, one at a time
4) delete the empty changelist
If there's a shortcut to do that, I'm all ears (eyes, whatever) !
But I would still like to learn how to do what I originally asked.
BTW, I do NOT have admin privs :-}
Thanks !
For the specific case of undoing a shelve operation and putting the shelf's contents back into the default changelist you could use p4 revert followed by p4 unshelve.
For the general case, if you just want to reopen everything in the default changelist you could do:
p4 reopen -c default //...
If you have a bunch of changelists and you want to just move the files from change 123 into the default changelist that'd be more like:
p4 -F %depotFile% opened -c 123 | p4 -x - reopen -c default

How to revert file but leave it in pending changelist?

In Perforce P4V I have a file in a pending changelist. I want to revert the contents of the file but keep the file in the changelist. How can I do that?
I tried Perforce's revert command but that removes the file from the changelist.
The only way to accomplish this (short of copy/pasting the original contents back into this file, but that seems silly) is to revert and reopen it. Shelving, by itself, does not revert the file. The concept of "shelve and revert" is still two operations.
This is not readily possible, as other respondents noted.
If you are okay with a multi-step solution, you could
Right-click the file in the changelist and choose "diff against have revision".
In the diff window, under "Edit" choose "Edit right/left pane" (whichever side yours is
on).
Copy the contents of the original and paste them over your edited workspace version
Save the file.
Your file now has no changes, and it is checked out in the same changelist.
Using the command line, it can be done in three stages. If you are using windows I highly recommend having a unix environment, e.g. cygwin (which is the one I used.)
Assume your changelist number is XYZ and you have shelved the files in their current revision (just for the sake of it!)
Step 1: get a list of files and put them in a temp file.
p4 describe XYZ | grep \/\/ | sed -e 's/\.\.\. //'| sed 's/#.*//' > temp
Step 2: revert all the files in the changelist
p4 revert -c XYZ //...
Step 3: check out / edit the files again
cat temp | xargs p4 edit -c XYZ
I assumed all the files are in edit mode (i.e. not an already opened file or a deleted file).
PS : delete temp, if you are fussy :)
I don't believe this can be done, even from the command line, since p4 sync (even with -f) explicitly excludes operations on open files.
The feature you're looking for is shelving. This will revert the file, but keep a shelved version in the changelist, which you (or someone else on a different client) can unshelve later.

Get the changelist number of current workspace directory

Each time we do a build, we have to record the changelist number of source files for tracking. We have different projects (under different directories) and they are synced at different changelist number. May you please show me how can we get the changelist number of a specific directory?
Also, there's p4 changes -m1 //path/to/your/project/...#have which, if run in the client workspace that synced the files for building, will give you the highest changelist number of the files in the workspace.
You can also use the short version p4 changes -m1 #have if you don't want to specify the directory.
If you are using a shell for which "#" is a comment character like bash, remember to escape it as follows: p4 changes -m1 \#have
p4 cstat //path/to/your/project...#have |grep -B1 have|tail -n2
#thegeko, this does not require high max_scanrows perforce limits
If your build system always syncs to head on the directory before building, you can use p4 changes -m 1 //path/to/your/project/... to get the head changelist number for that directory.
If you go with this method, I would suggest running the changes command before syncing, and then explicitly syncing to that changelist. That should eliminate the chance of someone checking in between the changes command and the sync command.
I use the "lazy manual way" (aka I don't know better) within the P4V client:
Use this in the "Submitted" tab filters: //yourproject/...#>have
And it will show you which CLs you haven't synched, note the oldest one.
Remove the #>have filter and see what's the CL that came before the one you just noted.
From within the directory:
p4 changes -m1 //...#have
Using just the workspace path, p4 changes -m1 /path/to/your/workspace/...#have (or cd /path/to/your/workspace; p4 changes -m1 $(pwd)/...#have) gives you the highest changelist number of the files in the workspace. This is similar to the accepted answer above from user1054341 p4 changes -m1 //your-client-name...#have, but you don't have to remember the client name.
A path to a subdirectory in the client gives you the latest changelist in that subdirectory and its children, e.g. p4 changes -m1 /path/to/your/workspace/src/module1/...#have. This can be run from any directory within the workspace.
Omitting #have shows the latest changelist checked in to the depot.
These commands must be run from a directory in the workspace.
In my case, I just want to know what changelist number is opened (not syned to) in a specific directory. For that, I do:
p4 opened -s | cut -d' ' -f5 | uniq

Showing a change in a shelved perforce file

If a colleague has a file shelved in perforce, and I'd like to diff the file in the shelved changelist against the source version of that file what is the perforce command needed to do this?
For example if the file a.txt is shelved in changelist 156222 how do I view the changes to a.txt that are in the shelved changelist vs. the current review of a.txt
If you know the revision of the shelved file (e.g. #4) and the head revision (#3 in this case) you can use
p4 diff2 //path/to/depot/file#3 //path/to/depot/file#=<changenumber>
or - even easier - you can use p4 describe (see manual):
p4 describe -S <changenumber>
Find the changenumber with:
p4 changes -u <user> -s shelved
If you are using P4V, you can go to your Pending tab and select the "User" and "Workspace" of your colleague (with the help of the drop-down "Browse..." option).
Then you will see his/her Pending lists, being it composed of shelved files or not. From there, the normal "Diff Against" will work for the "a.txt" file.

Is there a single Perforce command to display a list of all the check-ins to a file/dir along with the list of files that changed and the description?

p4 changes -l ... shows us the list of check-ins and the description, but it doesn't show the list of files that were modified in the check-in. Is there a way to do that in one command, without the need to create a wrapper script that combines the output of another command like p4 describe or p4 file?
In Subversion, I can do this by running svn log -v.
The 'files' command can do what you're looking for. An easy way is:
p4 files //...#=<changelist>
That example will list the files modified by that changelist, under the view specified.
You can use the "describe" command to get the description of a changelist, along with the files affected.
For example, p4 describe -s <changelist> will describe the changelist, and the "-s" will prevent it from displaying file diffs.
One liner, list all changes made to a branch, with description and list of affected files, without showing the diff. Thanks to a combination of answers. Works on windows with Unix utils
p4 changes -s submitted //depot/xxx/yyy/zzz/... | grep -o "^Change [0-9]*" | cut -f2 -d" " | p4 -x- describe -s
Output:
Change 1753385 by user#clientspec on 2019/03/08 06:29:44
Changing the world
Affected files ...
... //depot/xx/yy/zz.h#6 edit
Change 1751752 by name#clientspec on 2019/03/05 15:24:00
I made a change to a file
Affected files ...
... //depot/xx/yy/zz.h#3 integrate

Resources