Perforce diff file against a specific changelist - diff

Is there a way to quickly diff a file(edited in my current work area) to same file submitted in an earlier change list in perforce ?

Yes, you can specify any revision of the depot file to diff against. For example, if that 'earlier change list' was change 1742, you can simply do:
p4 diff myFile.txt //depot/path/to/myFile.txt#1742
There are lots of ways to specify the desired revision of the file in the depot. Run
p4 help revisions
for all the details, or see: http://www.perforce.com/perforce/doc.current/manuals/cmdref/filespecs.html

Related

Perforce Commandline Get Contents of Deleted File

I've done this several times in git, but not sure how to do it in p4 commandline. Google is not helping me - or maybe I'm not searching correctly.
I have a file that was deleted: /path/to/file/index.html Now, I need to get the contents of that file as it was before being deleted. I do not want to bring it back to life, I just need the contents.
The changelist for the delete is 125325.
What would be the easiest way to do this?
To sync it to your workspace (this is kind of similar to the git checkout method that you're probably familiar with):
p4 sync /path/to/file/index.html#125324
If you just want to see the content (e.g. dump it to stdout), you can use p4 print (if you were to use the depot path of the file rather than a local path, p4 print doesn't require that the file is mapped to your workspace):
p4 print /path/to/file/index.html#125324
Note that the rev specifier I'm using is the changelist before the file was deleted. You can also use the prior revision number, or an earlier rev/changelist, a particular date, etc. See p4 help revisions for all the ways you can reference older versions of files.

Perforce tkdiff

Is there a way to do a tkdiff on two Perforce changelist versions of the same file? In my previous job, where svn was used, I could use -r with tkdiff to get revision numbers. For example:
tkdiff -r323262 -r314735 [filename]
That's not working in the Perforce environment. Is there some feature like that with Perforce?
Thanks everyone. What worked best for me was p4v. The Perforce Visual Client let me tkdiff between selectable versions of a file.
Just drop the hash '#n' in the perforce file rev number and pass it to '-r' of tkdiff.
e.g. tkdiff -r4 -r5 filepath will give you the diff between versions filename#4 and filename#5 .
Using p4v is the best way to diff between two files, either by doing 'Diff against Have Revision', or starting 'Revision Graph' on a file, then dragging and dropping between the two revisions you want to diff.
In P4V you can stiff use tkdiff, by going into Edit->Preferences, then changing the Diff program to tkdiff,
tkdiff will then be used for 'Diff against Have Revision' or diffing between revisions in the Revision Graph view.
I used tkdiff in preference to P4Merge for a long time, until I discovered Beyond Compare.

Perforce - create patch file of differences against have revision

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.

perforce: sync to an earlier revision

I want to test a fix and to compare the behavior before the fix vs. now; I need to sync to a the earlier version. So, if the fix was committed in revision x; how can I sync to one revision before, say x0?
Say that you want to go back to revision 'n' from revison 'n+1' (rollback). You can take the following steps:
p4 sync ...#n
This will sync your files to the older version that you want
p4 edit ...
Open all the files for edit or do "p4 edit filename" to open only a particular file for editing.
p4 sync ...#n+1
Before submiting you need to sync files to the latest revision on the repository.
p4 resolve -ay
This will accept the changes that you have made, ie, revert all the changes done when you moved from revision 'n' to 'n-1'. So effectively, all your files have been rolled back to revision 'n' in your local repository.
p4 submit ...
Go ahead and submit the changes. This will roll back all main repository to revision 'n'. Effectively the revisions 'n' and 'n+2'(current) will be identical.
p4 diff2 -q repository#n repository#n+2
This is just to verify if have rolled back the files. This should show that you have no differing files in the two revisions.
I found the answer while writing my question. I have been trying:
p4 sync ...#x0
where x0 is the changelist before the change containing the fix. But only a fraction of files was getting reverted. I found the issue that when we specify ... only the files in that folder and subfolder(s) get synced. So above command should be executed from the root of the workspace.
If you want to sync a specific version number (not changelist number) for a specific file. This worked for me:
p4 sync //your/depot/path/and/file.name#1
to verify you have the version you want, you can use the have cmd
p4 have //your/depot/path/and/file.name

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.