p4 unshelve doesn't bring new added files - perforce

It seems that p4 unshelve -s changelist doesn't bring the new source files that are added in the shelved changelist. Two questions:
Am I missing something?
Any workaround?
Thanks.

p4 unshelve should faithfully open every file that was shelved, for its corresponding action — add, edit, integrate, or delete. The opened file will be opened at the same working revision, with the same resolves (either pending or completed), and the same content.
To answer your two questions:
Yes, you missed something (but there's not enough information to know what).
To work around the problem, figure out what you missed and fix it.
Do the added files show up in p4 files #=SHELF? If not, they were never shelved in the first place. Go back and fix that.
Do you get an error message from p4 unshelve telling you that these files can’t be unshelved? If so, fix that.
Are the files already opened according to p4 opened? If so, either they did get unshelved or that’s the reason they couldn’t be unshelved.

I faced the same issue but for my case it's because of I have file(s) opened for add locally. Target shelved CL that I want to unshelve also has that file(s) opened for added as well. So if I try to unshelve target shelved CL, it will shout out similar to the following error message.
//depot/dir/file.h - can't unshelve (already opened for add)
So I have to do the following
p4 revert <file(s)> - revert all files opened for add. This won't remove the file(s), it will still be there. It will show message like //depot/dir/file.h#none - was add, abandoned
p4 unshelve -s <target-CL> - to unshelve target CL again, this time, there should be no error message. If you already unshelved previously but has error for those file(s) opened for added only, then you can do just p4 unshelve -s <target-CL> <file1> <file2> to unshelve only those file(s) opened for add only.
Done, now you can continue working.

p4 unshleve will open files for add if they existed in the changelist passed to -s.
There exists a case where added files specifically wouldn't be unshelved and that is when the files already exist and are writable. For such files, you should be seeing an error saying:
Can't clobber writable file /file/path
I used to run into this case when I do the following:
Shelve a changelist that has files opened for add on workspace1
Unshelve the changelist on workspace2
Revert all the unshelved files on workspace2, including the files opened for add
Now the files that were opened for add will exist in workspace2 and stay there in a writable state
Unshelve the changelist again on workspace2
If you inspect the output of p4 unshelve here you should see the error mentioned above
Run p4 opened on workspace2 and not find the files that were opened for add

Related

Deleted (not submitted) directory in Perforce: cannot revert, force-sync, reconcile or do anything else

I have deleted a directory in a 3rd-party Perforce client. It should have used p4 delete, but I cannot be sure. It was not submitted.
Now:
I don't see the deleted directory in p4v.
p4 revert fails:
p4 revert //depot/path/deleted-directory/...
//depot/path/deleted-directory/... - file(s) not opened on this client.
I cannot force-sync deleted-directory to revert the deletion:
p4 sync -f //depot/path/deleted-directory
//depot/path/deleted-directory no such file(s).
p4 sync -f //depot/path/deleted-directory/...
//depot/path/deleted-directory/file1.txt#2 - deleted as /Users/me/depot/path/deleted-directory/file1.txt
I cannot reconcile them:
p4 reconcile //depot/path/deleted-directory/...
//depot/path/deleted-directory/... - no file(s) to reconcile.
p4 opened doesn't see them:
p4 opened
File(s) not opened on this client.
How do I get this deleted directory into a changelist or at least revert it?
I tried all suggestions from "I've deleted all the files in my directory. How can I get them back?" except for checking out a new workspace, which I will eventually do.
Short answer:
p4 undo //depot/path/deleted-directory/...#head
p4 submit
That will undo the head revisions in that directory (i.e. the deletion) by creating new revisions that are copied from the prior ones.
Longer answer to explain why all the things you tried didn't work:
p4 opened and p4 revert both operate on files that are currently open. If you hadn't yet submitted, then revert would put the files back, but since this deletion was already submitted, there were no open files to revert.
When you force-synced you were just forcing a re-sync to the head revision, which is deleted (just like the files in your workspace), so no matter how hard you force the sync all you're going to get is a lot of nothing. If you had done:
p4 sync "//depot/path/deleted-directory/...#<head"
in order to sync to the revision prior to #head, that would have done the trick. Note that no -f flag is necessary. Once the files were synced to the correct revision, you would also be able to undo the delete by following that sync command with:
p4 add //depot/path/deleted-directory/...
p4 submit
Similarly, reconcile didn't do anything because the files are deleted at the head revision and deleted in your workspace, so there's nothing to reconcile. If you wanted to get really weird with it you could undo the delete via reconcile by using a combination of sync and flush to simulate the condition of having re-added new copies of the files:
p4 sync "//depot/path/deleted-directory/...#<head"
p4 flush //depot/path/deleted-directory/...
p4 reconcile //depot/path/deleted-directory/...
In addition to being unnecessarily complex, this reconcile-based solution will lose the information of which revision the re-added files came from (thanks to the p4 flush), so I would not recommend it. Go with undo and if you're on an old server version that doesn't support that do the normal sync/add thing.

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

How to do I get files I deleted locally but didn't commit the changes?

I have deleted some files/folders in my local machine but I did not commit the changes to repository.
How to get the deleted files back?
I am not getting the deleted files after performing the p4 sync -f. Why I am not getting the deleted files after the force sync?
If you haven't reverted the changes Perforce will still think you want to delete those files so won't restore them.
You need to go to the pending changelist and do a "revert" on those files to get them back.
Use the "p4 revert" command:
p4 revert -c default //...
This "revert[s] every file open in the default changelist to its pre-opened state."
Source
If you don't want to revert all the files, move the files you want to revert to a separate changelist and use the "-c" option.
If you only have a few files to revert you can specify the name of the file:
p4 revert lib/libopenssl.a include/openssl.h
for example, reverts exactly those two files (thanks to Bryan).

How to unshelve a shelved changelist to another branch prior to Perforce 2013?

Using Perforce Server 2012.2/538478, how can I unshelve files from the trunk to another branch?
When trying to do it, I get:
//filename... (not mapped to your workspace view)
In Perforce 2013, I found this unshelve command to really be helpful:
p4 unshelve -s <changlist#-with-shelved-files> -S //depot/streamname
But with the version I'm using currently, I found nothing to help me with that issue.
Any suggestions?
The other answers didn't work for me, this is what I did using perforce 2014:
Edit your current workplace so that both //depot/product/B1/... and //depot/product/B2/... are mapped in it (not to each other, to your workspace like normal mappings)
In P4V, go to "Branch Mappings" (View menu->Branch Mappings )
Ctrl+N to start a new mapping (or right click the list and choose "New Branch Mapping..." )
Under "Branch Mapping" provide a name like B1_TO_B2
Replace the mappings under View to be for example
//depot/product/B1/... //depot/product/B2/...
OK
Create an empty Changelist where your unshelved files will be placed (otherwise they will go to "default" changelist). The number of this new changelist will be < TARGET_CL > in the command below.
In the command line, run
p4 unshelve -s <SOURCE_CL> -c <TARGET_CL> -b B1_to_B2
If it doesn't work, make sure the correct workspace is set in .p4config
Now all you have to do is resolve the files in < TARGET_CL >
You're looking at the right command, but possibly not the right parameters. This is how I use it:
p4 unshelve -s 77655 -b MY_BRANCH_SPEC
which unshelves changelist 77655, using the specified branch specification to map the files to the new branch.
Critically, you need to make sure that both the specified branch mapping and your current workspace mapping contain both the source and destination files, otherwise you will get the "file not mapped" error.
Unfortunately, without upgrading to 2013.1 and getting the improved unshelve operation, you're going to need to manually copy the data by:
unshelving in trunk, noting the specific files that have changed
p4 edit the files in your other stream/branch
manually copy the unshelved files to the other stream/branch (you can't use p4 copy or p4 integrate for this because they aren't committed on the trunk
test and commit on the other branch
After spending sometime searching and reading, I have not come across a concrete example for unshelving a shelved changelist to another branch. finally I put together a concrete example.
Assuming you have a shelved changelist 324426 in Branch B1 and want to unshelve it to Branch B2.
I was able to create branch spec, then unshelve changelist to another branch.
here is exactly what I did:
1. Create a text file named branchSpec.txt, with the content below: set you own Branch name and View.
Branch: B1_to_B2
View:
//depot/dev/main/B1/... //depot/release/B2/...
2. p4 branch -i < branchSpec.txt (in target directory)
3. p4 unshelve -s 324426 -b B1_to_B2 (in target directory)
Viola, shelved files in changelist 324426 in B1 now is unshelved to B2 and ready to be submitted.
A way how to get around this is in P4 2012:
Manually copy and overwrite the branch with the trunk
Right click the branch in P4 client and click 'Reconcile Offline Work...'
This will allow you to select the new and changed files and add them to the changeset.
You can use P4 unshelve for this, but you have to create a branch mapping namely A_to_B.
1] p4 unshelve -s CL_NUM -b A_to_B
2] p4 add (files opened for add)
3] p4 resolve
Note: Please do not forget step 2. P4 do not open them by default in your destination branch. You can confirm that with "p4 opened"
This what helped me to unshelve a change list from one branch to another.
Let's say you have a shelved change list #112233 in a source branch: "//depot/release1/main/" that you want to unshelve to a destination branch: "//depot/release2/main/" .
Create a branch spec in a text editor:
nano branch-spec.txt
Branch: R1_to_R2
View:
//depot/release1/main/... //depot/release2/main/...
Create a branch
p4 branch -i < branch-spec.txt
Unshelve Changes
p4 unshelve -s 112233 -b R1_to_R2
Resolve
p4 resolve
I think what you really need is "p4 move -f". It's explained in detail here: p4 move -f: What It's For

Resources