Perforce - create patch file of differences against have revision - diff

In Perforce, how can I create a patch file which has the changes that are in the file as currently saved, compared to the have revision? Instructions for either the GUI client or the CLI client would be great.
I can see how to get the diffs between two changelists, but not how to just get the difference between the last changelist and the current state of the files. Additionally, I can see that in the GUI client, I can right-click on a file and select "Diff Against Have Revision" from the contextual menu, which shows me what I'm looking for, but I can't figure out how to get that into a file.
I'm basically looking for the equivalent of what git diff <file> > patch.diff does in Git-land.

I think that p4 diff -du FILE > patch.diff should do what you want.

Single file
p4 diff -du file > file.patch.diff
Every file
p4 diff -du > patch.diff

The problem with p4 diff is that it doesn't take into account of new files. Also you can't get files that are only in a certain pending change list.
If there is a pending changelist, you can actually use an open source perforce patcher tool, which I have created for my project needs. You can directly download from this link of github.
In case you want to checkout the source, go to the github repo.
Documentation for the tool can be found here.

Related

How to checkout from diff view?

I am using Perforce 2015 client (P4V) on Windows 7.
I changed some files in my IDE. Then I use "Folder Diff" in Perforce to locate them. I was expecting to find "checkout" right click menu on the "Folder Diff" Perforce window in order to move my changes to a changeset but I don't see any "checkout" around.
How can I checkout directly from Diff view?
If you changed files on your workstation, but Perforce doesn't know about those changes yet, the command you're looking for is "reconcile".
I believe that P4V's Folder Diff may only show you the reconcile options if you use Folder Diff from the Advanced Reconcile Options variant of Reconcile Offline Work.
So to perform this style of Folder Diff within P4V, you should start by context-clicking on the root folder in your tree view and choosing "Reconcile Offline Work", then choose the Advanced Reconcile button at the bottom of that display, as described here: http://www.perforce.com/perforce/doc.current/manuals/p4v/Offline.html
Then, when Advanced Reconcile opens up the Folder Diff, you will see suggestions in red lettering about what your options are for each file (Mark For Edit, Get Revision, ec.). You can then pick one of those options by context-clicking that file in Folder Diff.
Alternatively (and perhaps more useful, once you get used to it), you can do this from the command line. If you haven't worked directly with the command line before, you can context-click "Open Command Window Here" on the root folder of your workspace treeview to get to the command window. Then, type
p4 status
to see a report about what changes you have made to your files, and
p4 reconcile
to make those files open for add, edit, or delete, as appropriate. Then close the command window and refresh P4V to see them.
I am not sure what your exact scenario and IDE is. I am using Visual Studio with the Perforce plugin, and when I make any changes in my source this plugin will check-out this file automatically (you can also choose to be prompted). So no need for folder diffs to locate any changes.
Should your IDE miss any integration plugin's then a very simple workflow could be like this:
Go to Perforce and check out all the files in your solution
Make your edits in your IDE (online or offline doesn't really matter)
In Perforce choose 'Revert Unchanged Files' on the changelist
And voila, only the changed files will be left in your changelist, you can then review the changes and submit to the depot.
NB: should in the mean time another developer have made any changes to any of your changed files, Perforce will warn you that you need to execute a Get Latest and then Resolve (i.e. merge) the changes.

Perforce - How to get the list of files that have been modified locally?

I am looking for a perforce command to get the list of the files that have been modified locally and "not" checked-in to the repository.
I understand that I "should" get the list of modified files in Pending changelist, but there are scenarios when I don't get to see a modified file in that list. And then on "manually" checking out a file and doing a diff i realize the difference.
Is there any command that could check all the files in a given folder and provide me a list of files that are not same as there state in the repository?
I tried "p4 sync", but that did not work.
Thanks for your interest.
Try
p4 diff -f -sa
(see manual for further details)
I use "p4 revert -n ./..."
where
-n
List the files that would be reverted without actually performing the revert.
This lets you make sure the revert does what you think it does before actually reverting the files.
In the recent versions of Perforce, try "p4 reconcile -e"
see: http://www.perforce.com/perforce/r12.1/manuals/cmdref/reconcile.html
It certainly takes its time though (not very fast).
I think, the modified files are submitted locallay (Otherwise, p4 opened ./... will help to find)
If files are already submitted to local perforce and still want to know which all are modified..
p4 changes -m 5 ./... (Should give changes lists)
p4 integrate -n ./... //server/code/base/... (This should list the files to be integrated to mainline.

cvs editors does not work from many places in the same project

I am using cvs for a project. I check out a copy of the project from the repository using cvs checkout ... and then use cvs edit <file> for editing them. Now, consider the sample directory structure for my project below:
project/:
dir1/:
sample1.C
dir2/:
sample2.C
Now assume that I run the following commands:
cd ~/cvs/project/dir1/
cvs edit sample1.C
cd ../dir2
cvs edit sample2.C
cvs editors
My output will contain only sample2.C and no mention of sample1.C. If I cd into dir1 I can see only sample1.C as being edited. My questions are as follows:
Is there something wrong with my cvs settings? Or should I invoke the cvs edit command from a single place for whatever file I need to edit in order to see all the files being edited in one place.
Is there a command in cvs which I can use to see all the files being edited in cvs across projects?
P.S: Please let me know in case more details are needed.
cvs commands by default work on the current directory and below. So in your example, because you are in dir2, you are only see sample2.C. If you moved back up to the proect directory you would see both files.

Use perforce to capture current state of external directory

I have a directory outside the repository. I put generated sources in there. These generated sources take FOREVER to create. Rather than have everyone on the team generate these sources, I would like to use our build machine to generate the sources, and check them in to perforce. How do I do this and ensure that the source controlled directory only has only the most recent files and not any that were generated previously but not in the most recent build?
I was thinking of doing a p4 edit on all the files in the generated directory (for existing files), then doing a p4 add using wildcards to get any files that are new, but I do not know how to handle files that were previously generated, but not generated in the most recent build (should be deleted).
Start as you suggested - p4 edit and p4 add to capture all changes, then call
p4 revert -a
Which will revert any file in the depot that is open for edit but is actually unchanged or missing.
I found this on the perforce blog and it is exactly what I was looking for. Automating folder replacement using P4Java and Apache Ant
One idea is to, before the build, removing everything in this area manually (not through Perforce, but through the OS). After doing the build, do a "Reconcile Offline Work". This will reconcile in Perforce what you have in this area by adding new files, deleting ones that are not there anymore, and editing those that have changed.
You can reconcile offline work through P4V, as seen here. In your workspace browser, right-click the folder and choose "Reconcile Offline Work".
Or, you can do it through the command line if you prefer a more automated solution, as seen here. (Note: this link also talks about reconciling through p4v, but this is superseded by the previous link)
p4 diff -se //myclient/... | p4 -x - edit
to checkout changed files.
p4 diff -sd //myclient/... | p4 -x - delete
to delete files.
find . -type f -print | p4 -x - add
find . -type l -print | p4 -x - add
to add files and symlinks in Unix, or
dir /s /b /a-d | p4 -x - add
to add files in Windows.
For Binary files in Perforce you can set a FileType flag that only stores 1 (or a set number ) of revisions for the file in the repository. This way you will have history of the file but your other users will only have access to the binary for the latest version of the file and also your server will only store one copy which is much more storage efficient if you dont need to store multiple copies.
To make the change.
Add the files you are interested in to the repository.
Check out the file.
Right click in P4V and select Change Filetype
On the dialog pops up select +S "Server limits the number of revisions stored" at the bottom of the screen, which will restrict the number of files stored.
Hope this helps.

How to undelete a file with Subversive?

Please note: This is a question about the Eclipse plugin Subversive, and not about Subversion itself. Please do not change the title to be about 'Subversion'.
So I deleted a file that I really shouldn't have.
I've found various approaches to restoring the file outside of Eclipse/Subversive, but I was wondering if there was a best/easiest-to-use/history-restoring way to restore the file using the Subversive tool.
Select the folder in the project that contained the deleted files.
Right click, select Team > Merge...
On the URL tab, set the URL to the server URL for the same folder.
In Revisions, select Revisions and enter a range that includes the deletion, e.g. 1000-1001, or use the Browse button to select them.
In Revisions, enable Reversed merge
Click Preview and check that it shows an Added entry for the files you plan to restore.
Click OK - Eclipse switches to SVN Merge in the Synchronize view.
In the Synchronize view, right click the files you want and select Accept
In the Synchronize view, use the Synchronize SVN icon to switch from SVN Merge to SVN, where you can see the restored file as an outgoing change.
If you have already submitted the remove then it's now time to roll back to the earlier version. In Subversion you do that with "svn merge", where you merge "backwards" from the current to the previous version.
Say you did this:
$ svn rm file.txt
$ svn ci -m "don't need that file"
Committed revision 1325.
Now you want to undo this and restore the old revision 1324, i.e. the state just before the remove (the dot is for 'current directory'):
$ svn merge -r1325:1324 .
If you are unsure you can do a dry-run first, where svn will print the output of the command, but not actually do anything:
$ svn --dry-run merge -r1325:1324 .
The result should indicate that the file is being added (again):
A file.txt
you could switch to revision where this file was exist. Edit/copy this file and switch back to the head revison and commit it here.
Also you could merge changes beetween two revisons - head and last revision file was exist in repository and apply changes to your working copy.
Just "Show History" on the folder, file was existing in. Then click through the history and find the lost file.
I guess you're hoping to not resort to the command line but in case it's useful as a last resort, see this question for how to do it from the command line: What's a simple way to undelete a file in subversion?
Easier: try to commit, Eclipse will show you the dialog with the changed files, click on the one you want to delete with the right button and pick "Revert".
I had a similar issue, I deleted a set of files related to a feature that after a couple of months I want to recover.
The most straightforward solution in my case was to check out in a separate directory the whole project as it was before the file were deleted.
To do this from the Eclipse Repository View go to your project, right click "Check Out As...", in the modal window write the destination folder, select a suitable date of the past in which the deleted file existed (weird, my plugin does not give the possibility to choose a given revision..) and check out.
Now you can easily search, find and copy-paste the files you want to recover.