P4V - remove identic files but with different history from changelist - perforce

I shelved files from another branch and unshelved them in the current branch. The problem is that now I have around 1500 files in the changelist and I want to remove the files that are identical between the branches. I've tried with Revert Unchanged Files and it reverts 0 files, but when I individually diff them I get the message that they are identical.
So, how can I remove them from the changelist if they are identical to the current version.

I don't think P4V has an equivalent to this, but this is a one-liner at the command line:
p4 diff -sr | p4 -x - revert
In P4V you can "open command prompt" to get a command prompt that already has the P4 client settings configured correctly; then just copy and paste the above.

Related

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 discard all uncommitted changes in Perforce?

What is the p4 command to throw away all my uncommitted change in my Perforce workarea?
When using Git, the analogous command is: git reset --hard
If you haven't checked out the files you've edited, first do
p4 reconcile ...
to get the changes tracked by Perforce.
You don't need this if the changes you want to undo are already in any changelist.
Then, from the root of your workspace,
p4 revert ...
(... is the Perforce wildcard for everything under a given directory, not something you have to fill in yourself).
If you also want to delete untracked files from the disk, then if you're using the 2013.2 release or later, you can pass -w to p4 revert to also delete newly added files. See this answer for some background on this option.
The reconcile step would first detect these files and mark them for add, and then the revert step would unmark them for add and delete them. If -w isn't available then there's no clean way to do this and the files will be left untracked and on the disk after the revert.
p4 revert is the command you're looking for.
Remember, if you want to revert a specified changelist just, you must specify its changelist number like:
p4 revert -c changelistnumber
Or, if you are not running it from the workspace root, specify the workspace/client name, like:
p4 revert //myWorkspace/...

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

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.

p4 diff does not show newly added files

I need some help.
How do I get diff using p4 diff so that my patch contains
information about newly added files too ?
p4 add foo.cc
p4 diff > my.patch
my.patch should contain foo.cc
p4 diff compares files on your client with what's in the depot on the server. If you haven't submitted your changelist containing the new file to add, then the file isn't on the server, so there's nothing to compare.
To use p4 diff...
Mark the file for add, as above ('p4 add //myworkspace/myfile')
Submit the changelist to add the file to the P4 server ('p4 submit')
Checkout the new file locally with 'p4 edit //myworkspace/myfile'
run 'p4 diff //myworkspace/myfile'
If you haven't edited the file since step 3, it shouldn't show any differences. If you edit the file after checking it out (and save your changes locally), step 4 will show diffs.

Resources