In Perforce, what changelist is assigned to a file after a resolve -am? - perforce

Server version: P4D/LINUX26X86_64/2013.2/938876 (2014/09/23)
My question is about what the resulting version number of a file would be after a "p4 resolve -am". Let's say I have a workarea in which I unshelve changes to my.file resulting in my.file#8 but the workarea has my.file#10 and there are conflicts. I do a "p4 resolve -am". I'm seeing that my.file is still my.file#8. Is that correct? Is there a way to tell if this is really neither #8 or #10 but the result of the merge of the two ?
Thanks!

A resolve -am modifies the contents of your working file (the one in your workspace), but does not create a new revision until you p4 submit. It does not change the pending changelist that the file is open in, nor assign a new submitted changelist to it.
The way to see what merges have gone into the working file is the p4 resolved command.
The p4 diff command will show you the line-by-line diff between what's in your workspace and the corresponding depot version (so if you did an unshelve into an edited file followed by a merge, this will be a combination of whatever diffs are in the shelf and whatever diffs you may have introduced in your own workspace). You can also specify a version argument to p4 diff to diff against arbitrary revisions (e.g. the shelved revision, an older depot revision, etc).

Related

Perforce Changelist and shelve command

I am very new to Perforce and just started using it.
After syncing my code using $p4 sync command i started editing a few files.
$p4 edit file1
$p4 edit file2
$p4 edit file3
These files were getting added to my default changelist. For collaborating with my team i wanted to create a changelist. For creating a changelist i ran $p4 change and removed "file1" from the changelist description. Now when i run $p4 opened. It gives an output similar to this.
//depot/... /file1 edit default change (text)
//depot/... /file2 edit default 111 (text+k)
//depot/... /file3 edit default 111 (text+k)
Now i have the following questions in my mind:
Which changelist am i currently working on is it default or 111 ??
what is the meaning of (test + k)?
When i make changes to file2 and file3 it is getting synced to changelist 111 and when i make changes to file1 it gets synced to default changelist . I am highly confused how is this happening ?
Also one more thing i am confused about is if do $p4 shelve will my changes disappear and will be reapplied only when i run unshelve command for the changelist created ?? Is this similar to git stash and git stash apply ?
It will be great if someone can answer these questions in detail. Any tutorial suggestions for Perforce will also be of great help.
Thanks in advance.
My recommendation for a Perforce tutorial is the Perforce User's Guide. Here's the section on changelists:
https://www.perforce.com/perforce/r15.1/manuals/intro/chapter.working_in_perforce.html#working_in_perforce.working_with_files.changelists
Which changelist am i currently working on is it default or 111 ??
Both! Both of these are pending changelists in your workspace.
what is the meaning of (text+k)?
The thing in parentheses is the "filetype". +k is a "filetype modifier" meaning that keywords (special words like $Id$ and $Revision$ and $Author$ in this file will be automatically expanded to appropriate values when you submit.
When i make changes to file2 and file3 it is getting synced to changelist 111 and when i make changes to file1 it gets synced to default changelist . I am highly confused how is this happening ?
Nothing is getting "synced" anywhere yet -- the pending changelists are just containers that reference the different files. When you shelve or submit, then the files associated with those changelists will get sent to the server and will be accessible by other clients. Since shelve and submit are changelist-level operations, only the files in those changelists are affected -- that's the point of having different pending changelists. You have all of the pending files in your workspace, but you can split up which ones get sent to the server at which times (it's a little like pushing different branches in git, but not -- you can do this on every operation in Perforce even when you aren't branching because each file is versioned individually rather than having the entire tree versioned as one atomic blob).
Also one more thing i am confused about is if do $p4 shelve will my changes disappear and will be reapplied only when i run unshelve command for the changelist created ?? Is this similar to git stash and git stash apply ?
No, p4 shelve only syncs the shelved change on the server with the local files in your workspace -- it doesn't in itself change your workspace. The equivalent of "stashing" would be to p4 shelve and then to p4 revert to wipe out the workspace changes. shelve on its own is a little more like doing a git push to a branch -- you keep your local copy but now it's also on the server (but not part of the "master" history). (It's not exactly the same though -- to be honest if you're brand new to Perforce I'd stick to regular old "submit" in a regular old branch since that's the basic workflow. Sharing work via shelves requires a lot more manual work since each shelf is like its own little mini-branch with no versioning.)

Perforce unshelve with merge from command line

How can I instruct perforce command line to merge files instead of overwriting them when unshelving?
The use case is the following: I have a shelf that changes "my_file". On a "clean" (p4 revert ...) owner of the shelf I update to the latest version. I then want to unshelve but the action should merge any potential conflicts instead of overwriting them. Is this possible via command line?
This is the command line version of How can I instruct Perforce to merge instead of overwrite or revert when unshelving a file?.
If your workspace is "clean", there will be no conflicts. The file will be unshelved at the originally shelved version; if you sync to a different version, that will automatically schedule a resolve.
If your local file is open, unshelving will schedule a resolve automatically (at least with current versions; older versions would refuse to unshelve over open changes).
If your local file is modified but not open, you might get the overwriting behavior you describe. Don't do that. :) Use "p4 reconcile" prior to unshelving to make sure that modified files are properly opened, or "p4 clean" to discard those modifications.

Reverting multiple checkins in perforce

I have made several checkins using perforce. I have no realized that all of them are unnecessary. I would like to revert all the changes for the last x revisions in the working directory, update the version number, and check in.
I am familiar with Mercurial. The way that I would it for that would be:
$ hg revert -r last_good_changeset .
$ edit version-number.txt
$ hg ci
Is there a way to do something similar in perforce?
In Perforce, a revert refers to restoring a file to the state it was in before it was checked out. What you're looking to do is back out a submitted changelist. This Perforce KB article has a few methods to do what you're trying to do, depending on your particular circumstance.
For example, if you have revisions #1 - #6 of a particular file, and you want to roll back to revision #3, you'd do this:
p4 sync myfilename#3
p4 edit myfilename
p4 sync myfilename
You're telling Perforce to get revision #3 from the depot, check it out for edit, then try to sync it back up to #head (the latest version in the depot). Since the file is checked out from an earlier revision, Perforce schedules a resolve so you need to tell it what you want to do with the file: accept the version in the depot, accept your local changes, or try to merge the two. You'll want to tell Perforce to accept the local version (or in Perforce parlance "yours"):
p4 resolve -ay myfilename
Now that it's resolved, you can submit it with:
p4 submit
If you have a series of files you want to do this with (for example, you've edited a bunch of files in a given directory and have checked them all in together several times, and you want to back out all of those), you can use changelist syntax as well. For example, if you want to roll everything back in a given directory to changelist 123, you can do this:
p4 sync //depot/some/path/*#123
p4 edit //depot/some/path/*
p4 sync //depot/some/path/*
p4 resolve -ay //depot/some/path/*
p4 submit
This will work for any revision modifier (see p4 help revisions for alternate methods of specifying the version you want).
The rollback function is specifically designed to do this. It goes back to a certain date/time or change list # and reverts all changes in the window you give it.
Simply right click on the file in question (P4V obviously) and select rollback. It will bring up this box. Not sure how to execute from command line...Ill see if I can figure it out and add that info.

How does one diff between two pending changelists in perforce?

I have a couple of similar pending changelists based on top of a branch of code and off the same workspace in perforce. I need to diff between them and (eventually) merge them together into one changelist. What is the fastest and simplest way to go about it? I would rather avoid creating a temporary branch.
Recent versions of the server support unshelving a change into a workspace with opened files, and resolving the merge.
So, assuming your server is recent enough, you simply:
Shelve the changes
Start with a clean workspace
Unshelve one of the changes into that workspace
Unshelve the other change into the same workspace
Resolve any merged changes that result.
Carefully examine your diffs prior to submit, to ensure you have the changes you desire.
The general answer to your question (where merging is not the goal) is that it's not possible with a p4 command.
You have to unshelve both changelists to different workspaces then run an external diff tool on the two workspace directories.
Try
p4 diff2 //repo/path/to/file#=shelf1 //repo/path/to/file#=shelf2
To compare all files:
p4 diff2 //repo/path/...#=shelf1 //repo/path/...#=shelf2
where 'shelf1' and 'shelf2' are your shelved changelists.
Caveat: you can only do a textual diff with 'p4 diff2'

re-submit changelist with new changelist number

I have submitted one file in perforce, and changes submitted by other user got reverted in merge.
Changes were not conflicting.
Is their a way, I can get that user's changes back. Means revert the revert.
Also how to submit a changelist again with new changelist number?
In order to revert a file (fall back to its previous version) you simply sync the previous version and submit that again.
For a single file the procedure goes like this:
# sync file at old revision (#3 in this example)
p4 sync //depot/file#3
# mark the file for edit
p4 edit //depot/file
# make perforce aware that something has to be merged
p4 sync //depot/file
# resolve (i.e. throw away the head revision changes and save those from #3)
p4 resolve -ay
p4 submit
If you have a changelist with several files (and not only edits, but also deletes & adds) the rollback is a bit more difficult.
See also this question.
Here's a smart script for that purpose and more info.
The 2nd part of your question I did not understand.
Submitting a change again with a new changelist number doesn't make sense, since a changelist contains diffs. If it was submitted once, then the diffs are already in the depot, so you can't submit the same diffs again.

Resources