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