Add a file to existing changelist - perforce

I edited few files in my workspace and did p4 change. Then I remembered that I have to make some more edits to additional files(not in the changelist). I opened those files with p4 edit but how to add these files to existing changelist. Is there a way to do it?

In general you can use:
p4 reopen -c CLN FILE ...
to move open files into the specified changelist (regardless of whether they were open for edit, add, etc.).
CLN may be default to dissociate the specified files from any numbered changelist.

You can say:
p4 edit -c changelist# file ...
where changelist# refers to the pending changelist.

p4 edit -c changelist file
same works for sd

file not open
p4 edit -c [changelist] [file]
file open already
p4 reopen -c [changelist] [file]
be lazy
p4 edit [file] && p4 reopen -c [changelist] [file]

Related

Perforce :Not able to create new changeList with Description

Not able to create new changeList for a file/files with Description
p4 --field Files=E:\MyFolder\run.py --field Description=Test change -o | p4 change -i
Shows error
Error in change specification.
Can't include file(s) not already opened.
Open new files with p4 add, p4 edit, etc.
Cant do it in single command, wanted automate.
Like the error says, you can't include files that aren't already open. To create an empty changelist, do:
p4 --field Description=Test change -o | p4 change -i
If you want to open the file for edit and submit it, you don't need to create a changelist explicitly. Just do:
p4 edit E:\MyFolder\run.py
(make changes?)
p4 submit -d Test
If you want to create a changelist that contains that file, you can take advantage of the fact that a newly created changelist will by default take ownership of files in the default changelist:
p4 edit E:\MyFolder\run.py
p4 --field Description=Test change -o | p4 change -i
If you have an empty changelist and files open in another changelist, you can move them over with the "reopen" command:
p4 reopen -c CHANGE E:\MyFolder\run.py
Note that this requires you to know the actual change number (CHANGE).
Finally, IFF the file is already open in the default changelist and you want to make a new changelist that contains that file and only that file, you can do this by specifying the file's depot path in the Files field of the changelist:
p4 --field Description=Test --field Files=//depot/run.py change -o | p4 change -i
A changelist description's Files field must contain the fully qualified depot path of each file, and it's only valid to include files there that are already open.
If you don't know the depot path of the open file, you can get it by running a command like p4 opened, which will list all open files by their depot paths.

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

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).

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