Can I remove a pending integration from an uncommitted revision? - perforce

I have an uncommitted changelist which contains a new file. I've integrated another file in (and I can see that operation in p4 resolved) but now I've changed my mind and want to remove the integration.
I could just revert the file and start over but it seems like there should be a better way. There could be other integrations that I want to preserve, for example.
Can I remove a specific pending integration without reverting the whole file?

I am not sure there is a way, because it is seems the granularity of Perforce is at the file level.

To preserve the content of your file, you could use
p4 revert -k [file]
p4 edit [file]
If necessary you could then integrate/merge and resolve with accept yours.

Related

Perforce: Additional edits after resolve

I've performed integration (p4 integrate) and then resolved conflicts in all files (p4 resolve ...). After that I noticed that one conflict could be resolved better by providing additional edits.
I want Perforce to think that the additional edits (after p4 edit file/in/question and vim file/in/question) are part of resolution, not an separate edit.
How can achieve this using p4 command line tool?
If you do p4 edit and make the edits, they will be part of the same atomic changelist and the same revision.
(It is possible to make the edits in such a way as to have them not get propagated back to the source on a reverse integrate, by "hiding" them in the merge, but you probably don't want to do this because it likely means you'll end up re-resolving the conflict later.)

How can I partially integrate a file in Perforce?

I have a file on another branch which contain a change I would like to integrate. But it contains other changes too which I don't want to integrate yet.
How can I integrate the file only partially?
I first integrated and resolved the file as usual, then I did a "p4 edit" on the file after that to remove the changes I don't want to go in yet. "p4 opened" said that the file is opened for edit, so I thought the commit will submitted as an edit not an integration. I was wrong! It still updated the integration history! So if I attempt to integrate the rest of the changes later the perforce will say "all revisions integrated", and the only way to resolve the problem is integrating by disregarding the integration history, which is painful to resolve.
How can I avoid this next time?
EDIT:
To clarify I mean there are multiple changes in a single revision of file and I want to integrate only a part of it.
(edited to reflect that the question is about partially integrating a revision, not integrating a single revision of a file)
Since a revision is the smallest atom of change in Perforce's metadata, you won't be able to record that a subset of a revision was integrated -- and since you don't want to record that the entire revision was integrated (thereby "ignoring" the rest of the revision for future integrations), rather than doing this as an integrate, I'd do it as an edit:
p4 edit target
p4 print -o theirs source#n
p4 print -o base source#n-1
p4 merge3 base theirs target > target
rm base theirs
(edit target)
p4 submit
Another option would be to initially open the file for integrate and then clear the resolve record by reverting (use the -k flag to keep local changes) and reopening for edit:
p4 integrate source#n,n target
p4 resolve
p4 revert -k target
p4 edit target
In general if there are multiple independent changes you're making to a file such that you might want to be able to cherry-pick and/or track them independently at a later date, submitting them as independent changelists will make that much much much easier. Shelving can help with this if you realize only after making a big change that it'd make more sense as a series of smaller changes -- shelve your big change, revert some parts, submit the smaller change, then unshelve the big change and continue.

How to sync locally modified file with server revision in perforce

I'm updating a locally modified file with the server revision so that I have all the latest changes (that other developers made while I was working on the file). I've already tried p4 sync. Does anyone know the correct way to do deal with this?
Thanks
If the file is opened for edit, and you have already run 'p4 sync', then you should have seen a message like:
$ p4 sync
//depot/main/b#2 - is opened and not being changed
... //depot/main/b - must resolve #2 before submitting
What this means is that Perforce is ready for you to merge your changes together with the changes from the new revision.
Perforce calls this process "resolving" the changes, and has told you that you must resolve them before submitting the file.
When you are ready to merge your changes with the new changes from the new revision, run:
$ p4 resolve
Many people find this process of merging the changes a bit complicated, and prefer to use a GUI tool. Try downloading the P4V tool from the Perforce website and it will help you merge the changes using a visual merge tool.
If you instead decide that you do not want to keep your local changes, and would prefer to discard them, and use the latest version of the file instead, you can discard your changes by running:
$ p4 revert
But be careful! This will lose all the unsubmitted changes that you have made to your file! The same is true of the 'sync -f' command and the 'p4 clean' command; these commands tell Perforce that you don't want your locally-made unsubmitted changes, and Perforce should replace the file with a clean copy from the server.
I will add more detail on Bryan's answer especially about all sequence of syncing, and fixing merge conflicts; assume that this is based on CLI p4.
Let's say you have locally modified files that upstream also has some updates for the same files since you've modified it locally.
Sanity steps I would do is the following
p4 sync -n :: with -n this is dry-run which it won't actually have any effect or perform anything yet, but will return output if it really performs. For the specific situation we're in right now, you probably want to look for the line that has ... in front + the line above it which says is opened and not being changed. With our situation, this means upstream files has updates for the file you've opened and probably made some changes to it. It needs to be resolved.
At this point, you can execute p4 sync to actually perform it.
p4 resolve -n :: again with -n which means dry-run. This is to check whether there's any outstanding conflicts you need to resolve as the result of your sync.
(if the output from 3. is not No file(s) to resolve.) p4 resolve -am :: this will perform conflict resolution automatically. It will try merging but will not do anything if there's any merge conflicts for target file. Its output will list out the result of each file. For files that it leaves out, there will be non-zero conflicts in the output.
p4 resolve -af :: perform merging manually. Its output will list out files (of course with their path).
From 5, edit each files as seen in the output. Search for ORIGINAL or THEIRS or YOURS then delete unwanted section, or merge things together as needed. When finish for each file, just save and quit. Do this for all files.
PS. More info for 6. Actually you can specify which merging resolution policy you want it to happen in which it can be
p4 resolve -at :: accept changes from upstream (accept THEIRS)
p4 resolve -ay :: ignore changes from upstream, only accept what you have locally (accept YOURS)
Also keep in mind, THEIRS doesn't need to always be upstream changes from depot, but if can mean a changelist that you just unshelved into your workspace locally.

Is there a way to get Perforce to revert unchanged files pending integration?

I'm getting ready to integrate our "Dev" branch into our "Testing" branch in preparation for an upcoming release.
For our last release, after the initial integration, we determined there were some changes we didn't want to release. I rolled back some files in the Testing branch, and commented out portions of other files. Many of these files haven't changed in the Dev branch, so as far as Perforce is concerned, they've already been integrated and are good-to-go.
Obviously, I could track down the changelists and un-rollback these files. I could also integrate the offending files with the "-f" option to disregard integration history.
But I was hoping to find a way to do this "automatically". I tried integrating the entire branch with "-f", resolving, and then reverting unchanged files, but this just gives the message: <filename> has pending integrations, not reverted.
Is there a way to get Perforce to revert unchanged files that are pending integration? Is there some other approach I should take?
Have you tried the following steps under 'Pending integrations not reverted'?
http://answers.perforce.com/articles/KB_Article/Reverting-Unchanged-Files
Files that are integrated and resolved but have no content or type changes will still be submitted as new revisions, EVEN IF you have 'revertunchanged' selected in your client spec, or use 'submit -f revertunchanged'. This behavior is by design, but is not obvious.
Again, if a submit would change the integration history of a file, then that file is considered changed, even if there are no content changes. In other words, updates to integration history are considered a file change, just like content, type, and attribute changes.
The command line equivalent of the 'revertunchanged' option, p4 revert -a, offers some context. From p4 help revert:
The -a flag reverts only files that are open for edit or integrate
and are unchanged or missing. Files with pending integration records
are left open. The file arguments are optional when -a is specified.
For example:
$ p4 revert -a b
//depot/test/b#1 - has pending integrations, not reverted
Users concerned about integrating files with no content changes are advised to use 'p4 diff -sr | p4 -x- revert'. For example:
$ p4 diff -sr | p4 -x- revert
//depot/test/b#1 - was integrate, reverted
Let me know if this helps.

perforce: create a local backup of current pendinglist

in perforce, i have a pending list with some changed files. now i want to revert to the base, but without loosing my changes, so i want to back them up somewhere. like saving the DIFFs of each file. at a later time, i want to restore those changes and continue my work.
is this possible? if so, how?
thanks!
there is no need for external tools at all, assuming you are on a unix machine (or have a proper cygwin setup under Windows, haven't tested it.) The only caveat is that Perforce's p4 diff produces an output that is slightly incompatible with patch, therefore you need it to point to your unix diff-command. In your client-root you can do
P4DIFF=/usr/bin/diff p4 diff -du > pending-changes.patch
optional (if you want to revert the open files from the command-line, otherwise use p4v):
p4 revert `p4 opened|awk -F\# '{print $1}'`
Later you would open the files for edit (can be automated by extracting the affected files from the patchfile pending-changes.patch and then:
patch < pending-patches
Depending on your path-layout in your client-root, you have to use the -p#num option of patch to get the patch applied cleanly.
You should be able to do a shelve. It's a way of saving a changelist for future editing. The link below is a Python add-in for Perforce that implements shelve. Also, I know that Practical Perforce has a couple of ways to shelve current changes without an external script. I don't have the book in front of me but I'll try to update this question tonight when I do.
http://public.perforce.com/wiki/P4_Shelve
Linked to from P4Shelve, is P4tar which looks very useful, and does the operations on the client, rather than branching on the server.
Certainly I'll be looking into doing similar things soon.
See also this question:
Sending my changelist to someone else without checking in.
It's basically the same thing.
Create a branch of these files in some appropriate location
Check out the branch versions of the files you have edited
Copy the edited files over from the trunk and submit them
Revert the files on the trunk
Now you've got those "diffs" you wanted safely archived. When your ready to apply those changes later on, just integrate them back into the trunk.
This is what the Python script, that Brett mentioned, does. This is the way to do it manually without any special tools.

Resources