Get a folder's changelist - perforce

If I select from Perforce a folder from my workspace->right-click->Folder History, in the new view that appears, there is a label: Changhelist: 1234. Is there a command line that can retrieve this information(e.g. p4 changelist d:/my_path)?

Yes, it's p4 changes. See: https://www.perforce.com/perforce/r14.2/manuals/cmdref/p4_changes.html
So: p4 changes -m 1 d:/my_path/... will show you the most recent changelist that affected files in d:/my_path/.
p4 changelists is the same as p4 changes, so you were very close with your guess, but there is no p4 changelist, just p4 changelists and p4 changes.
Try p4 help to see all the available commands.

Related

How to switch to a change-list when using perforce command line (p4)

I opened a bunch of files using p4 edit in my workspace and after making some changes on each of them, I decided to put them up for review so I staged them using p4 change and I got a number to mark the changelist. Once I did that I am not able to see the actual changes made in the workspace. The files have gone to a version prior to my p4 edit.
How do I revert my workspace to a changes pointing to a change-list?
p4 undo -c 403767
p4 undo #403767
p4 switch #403767
p4 revert -c 403767
None of the above seems to work. Also when I do a p4 opened -u <author-name> I have a string that says integrate change 403767 (text) for all the files listed.
The integrate change 403767 indicates that these files are open for integrate, so these can't be the files that you opened with p4 edit.
Files can be opened for integrate by the p4 integrate, p4 copy, p4 merge, or p4 undo command.
Further, if a file is listed by p4 opened, its current working state is already in your workspace. If you had opened the file for edit and neither reverted nor submitted it, p4 opened would say edit change 403767 and your edits would be in your workspace.
I will hazard a guess that what you are actually trying to do is integrate changes from another branch, and you're confused because those changes do not yet appear in your workspace. Run:
p4 resolve -am
p4 resolve
That might get things into the state you're expecting.

Perforce: How to revert all those files that are opened but unedited?

Is there a way to check all the files which are opened in the p4 client and can be reverted if we know that they are not edited.
In P4V, on the pending changelist in question, right-click and choose Revert Unchanged Files.
On the command-line, you can achieve the same with p4 revert -c CHANGELIST -a (you can even add -n to preview the operation). See p4 help revert for more information.

Perforce - Get files from a shelved changelist into default changelist , work on those files and again shelve them to a same changelist

I have created a changelist for review by shelving some files. Now I want to implement the review comments. For that I tried unshelving the files but p4 opened still shows that the files are in the shelved changelist and not in the default changelist. I want to work on these files and again shelve the modified files in the same changelist. How to do this using p4 commands.
If you intend to update the same shelved changelist, it's actually best if the unshelved open files are open in the same changelist number, and not in the default changelist.
The overall process for updating one of your existing shelves (number NNN) is:
Make sure your workspace is empty of any work in progress: p4 opened should say "file(s) not opened on this client".
p4 unshelve -s NNN -c NNN
work on your files using your text editor, etc. If you open any new files, make sure you do: p4 edit -c NNN so that the new files, too, are in the same changelist number. You can also discard a file from this changelist number by doing p4 revert if that need should arise.
When you are ready to update your shelved changelist, do: p4 shelve -r -c NNN. This replaces all the files in the shelved changelist with the files that you have open in your workspace at that changelist number. If there is only one (or a couple) of files that you wish to replace in the shelved changelist, you can alternatively do: p4 shelve -f -c NNN //path/to/file to replace just that one file in the shelved changelist
p4 revert -w -c NNN //... to clean all those modified files out of your workspace and leave the changed versions only in the shelved changelist
You can repeat this sequence over and over to revise your shelved changelist through multiple code review cycles.
Note that this is not the only workflow that you can use with shelves. For example, it's also perfectly fine, and quite common, for developers to prefer to create multiple shelves, where each shelved changelist represents a point in time through the evolution of your work as you respond to review comments, etc.
But updating a shelved changelist in place is also a good workflow, and I use it regularly.
Watch out for one particular "gotcha", though, which is why the p4 revert -w is so important: files opened for add. If you have a file opened for add in your shelved changelist, and if you do a simple p4 revert, rather than a p4 revert -w, Perforce will leave the added file's data in your workspace on your laptop, whereas the -w flag tells Perforce to delete that file from your laptop entirely. When you do the p4 unshelve -s NNN -c NNN, if the shelved changelist contains a file opened for add, and if a file by that name is already present on your laptop, Perforce won't unshelve that file (because it doesn't want to clobber the data that's already present on your laptop), and so it won't re-open that file for add in your workspace. It will give you a "can't clobber writable file" message when it does so, but if you absent-mindedly overlook that message, then you'll not have the file open for add anymore, and when you do the p4 shelve -r -c NNN, Perforce will remove that file from the shelf, and you'll have accidentally deleted that file from your shelf. It's easy to avoid this problem if you always reliably use p4 revert -w (so put 'revert => revert -w' in your P4ALIASES file).

Fastest way of submitting shelved changelist

I have shelved a changelist(say X) and I have ensured its correctness. Now i want to submit the changelist. I can
p4 unshelve -s X -c Y where Y is a new changelist i create before executing this command.
Then p4 shelve -c X -d and lastly p4 submit -c Y
Otherwise I can unshelve X, delete the shelve X and move the local copies to changelist X(p4 reopen -c X ) and submit X.
The last option is to unshelve X, delete shelve X, p4 change(and edit description) and finally p4 submit
What are your suggestions with regards to :-
Use 1/3 but copy paste the description that X already had to new changelists
Use 2 but copy each opened file manually in command p4 reopen.
The only advantage of 2 over 1 and 3 is that I don't have to delete X(because it turned out to be my submitted changelist, while in other cases it still is "pending").
The shortest method is:
$ p4 shelve -c #changelist -d
$ p4 submit -c #changelist
In the new 2013.1 release of the Perforce server, you can now do 'p4 submit -e X', which directly submits the shelf without needing to unshelve it first.
Try it, it's a great feature!
From my experience with Perforce, I would just unshelve the change-list, delete the shelved files and submit. Just make sure that the description of the change-list is accurate.
With Perforce 2013.1 or later, you can submit the shelved changelist "12345" directly:
p4 submit -e 12345
On previous versions, use this combination:
p4 unshelve -s 12345
p4 submit ...
Since it is 2018, here is an updated answer for newer perforce versions (2013.1 and newer)
p4 submit -e 123456
This command will fail if you already have that shelvelist open in some tree like so:
Change 123456 has shelved files -- cannot submit
In that case get to the root of that tree (or use -C client_name_where_shelvelist_is_open) and revert the changes before running the above command, like so:
p4 revert -c 123456 ...
p4 submit -e 123456

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.

Resources