How do I select the common base file manually for P4Merge? - perforce

I am trying to merge a file.
I have the main branch and another branch B that was branched from main.
Both branches have changes. The main branch was merged to B at some point; but the merge on B was undid directly afterwards. After some more changes on both branches I'm trying to merge again but perforce selects the incorrect base file revision from the main branch.
I need to be able to select the common base file manually so that it will do the merge correctly. Unfortunately I was unable to find any way of doing this. If anyone knows how to resolve this, that would be much appreciated.

If the merge was undone via the p4 undo command, you should be able to redo it with a regular merge operation by setting the dm.integ.undo configurable:
(p4 help undoc)
dm.integ.undo 0 Enable re-integration of undone changes
With that configurable enabled, the "credit" granted by each integration is considered to be nullified by an "undo" operation, making each previously merged revision eligible for a merge as if it had never been merged previously. (The default behavior is for the undo to be considered the same as an edit, so that it's combined with unmerged changes, but previously merged changes aren't re-merged.)
If that's not an option, the best solution is to use the -f flag. Specify the exact range of changes you want to merge, along with the -f flag, and the revision immediately before that range will be used as the base. E.g.:
p4 integ -f main/...#100,400 B/...
will use main/...#99 as the base for the resolve(s).

Related

What's the difference between p4 duplicate and branching and merging?

So in perforce, we have p4 integrate p4 duplicate p4 copy and p4 branch what's the difference and when should I use which?
C:\Perforce\test>p4 help branch
branch -- Create, modify, or delete a branch view specification
...
You can use this command to (optionally) create a branch spec for later use with copy, integrate, merge, and/or populate. Note that all of those commands can also take an on-the-fly mapping in the form of two file paths, and if you're using streams you don't use branch specs because the mapping is generated automatically based on the parent and child stream.
C:\Perforce\test>p4 help copy
copy -- Copy one set of files to another
...
Opens the target files in such a way as to create new head revisions that are identical to those of the source files. (This may in some cases overwrite changes in the target -- if you're using streams, there are guards on copy to help prevent this, but otherwise you should always use integrate unless you're absolutely certain that you want to overwrite the target.)
C:\Perforce\test>p4 help integrate
integrate -- Integrate one set of files into another
...
Opens the target files (and schedules resolves) in such a way as to create new head revisions that combine all outstanding changes from the source with existing changes in the target. Actually performing the merges is done via the resolve command prior to submit.
C:\Perforce\test>p4 help duplicate
duplicate -- duplicate revisions with integration history (unsupported)
...
Like it says, unsupported. This has specific use cases that you will hopefully never need to discover.

Perforce submit edited source file and branch/integrate/merge/copy from same source file in one changelist

Suppose we have a single text file in 2 branches:
//depot/work/branch1/file.txt
//depot/work/branch2/file.txt
We also have a central source file here that both branches depend on.
//depot/work/ImportantFile.txt
I make local edits to ImportantFile.txt and branch1/file.txt, but I also want to duplicate those edits to branch2/file.txt because ImportantFile.txt now expects all branches of file.txt to conform to a certain specification. As far as I know I have only 2 options, neither of which are ideal:
Manually make the same edits on both files and submit both changes in a single changelist. The problem with this, is that I would like P4 history to know that these files are still 100% integrated, but the history will show that they were edited independently.
Only make edits to branch1/file.txt, submit just this file as well as ImportantFile.txt in one changelist, then immediately integrate the change to branch2/file.txt in a 2nd changelist. Now the problem is that I've broken the build for a minute or two until branch2/file.txt gets the required changes.
How can I edit a file, and directly integrate those edits to another file before I submit those edits to the first file?
First off: you may already know this (and have had to make peace with it for reasons beyond your control) but:
ImportantFile.txt should not be outside of your branching structure. If your versioned files depend on it, it needs to be versioned itself, and that means it needs to exist independently in each branch, because branches are a part of your versioning scheme. Alternatively, maybe file.txt should not be branched, if it's required that it be identical in all branches at all times -- why branch something that's not allowed to diverge? But I suspect that just branching everything is the better solution.
Now for the workaround. (If you can't fix the root cause as described above, you've probably got a lot of this sort of thing in your future.)
p4 copy //depot/work/ImportantFile.txt //depot/work/NotABranch/ImportantFile.txt
p4 copy //depot/work/branch1/file.txt //depot/work/NotABranch/file.txt
p4 submit -d "Not a branch! (wink)"
Make your edits in //depot/work/NotABranch and submit them. Nothing is broken because, as stated, this is not a branch, and so it's exempt from whatever policy it is that forces all branches to move in lockstep. Now you can do:
p4 integ //depot/work/NotABranch/ImportantFile.txt //depot/work/ImportantFile.txt
p4 integ //depot/work/NotABranch/file.txt //depot/work/branch1/file.txt
p4 integ //depot/work/NotABranch/file.txt //depot/work/branch2/file.txt
p4 resolve
p4 submit
The merge history shows that both branches of file.txt were pure merges from a single common source, and so future integrations between the two should recognize that they don't need to be re-merged.

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.

Tortoise SVN Merge: Branch->Trunk with Revision History from both Tree

we cut branch from Trunk. Changes are done on both trees and committed. Now we want to merge branch to trunk with all the revision history from both. Is it possible?
Is manual merge is different from tortoise SVN merge say i have to do 3-4 files?
"Means i manually check the changes then do it on trunk and commit the trunk."
I earlier put a question regarding it but still confused.
Experts comment only.
Thx
You should be able to merge from your branch to trunk by simply right clicking on the target branch and selecting merge. Typically, a reintegrate merge will merge all changes from a branch back into the target branch. I have had failures with that in the past based on the version of svn, how merges have been done in the past, etc. At that point, I simply would do a 'Merge revision range' without specifying a revision. It then picked up the appropriate ranges to merge and successfully pulled those over to trunk.
Once the merge is done, you must commit the merges. Simply put, the merge operation completes on your local working copy. You will then have to commit the changes to your working copy in order for others to pick it up. I recommend doing merges on clean copies of branches/targets (meaning you have no outstanding changes on either branch). Also, make sure you commit any property changes as well.
Lastly, if you just want to merge a specific change, you can specify the revision in which the change was made instead of doing a full merge/reintegration.

exclude a changelist from p4 sync

Is there any easy way to exclude a specific changelist from p4 sync?
I want to sync up my code, but I don't want to fetch the changes from changelist #1337
Like: p4 sync //depot/source/... - //depot/source/...#1337?
The best way to accomplish this is just sync to head, and then use the 'Back out submitted changelist' function in P4V ('Submitted' pane, right-click the undesired changelist, select 'Back out submitted changelist').
This will create a new pending changelist in your workspace with the undesired changes removed.
It is possible by syncing to a range and using two commands to "skip" the changelist.
p4 sync //depot/source/... - //depot/source/...#0,#1337
p4 sync //depot/source/... - //depot/source/...#1337,#head
Note: you may have to specify the changelist on either side of the one you want to skip - not sure if the range is inclusive.
HTH,
Dennis
Ok this should work depending on what you want to do. Man I really miss git :(
If you simply want to sync and temporarily ignore a changelist you can do what the first reply said and back out the change list. Just remember to not check that change list in unless you want to wipe out the ignored changelist for the branch. However this approach will not work if you need to make changes to files that exist in the ignored changelist.
If you need to work with the same files from the ignored changelist you can do the following. One thing to note however, is that the ignored changelist will be pulled out of the remote branch until you are ok with them being in your code. (there is one other option but requires someone else to do something)
If you want to ignore a change list, and not get rid of it completely but simply be able to work on your code with it off to the side, the following will work.
Back out the changelist as previously stated.
Submit the backed out changelist to wipe out the changes in the remote branch. (don't worry)
Now do another back out but this time back out the chagelist created by the previous back out and shelve it. This back out of the back out will be a pending change list that is basically a copy of the one you wanted to ignore. Once its shelved you can go about your work, even in the same files. The down side is that now the ignored changelist only exist on your work space and its up to you to submit it or decide what to do with it at some point.
You can keep the ignored change list shelved until you know what you want to do with it. If, after you work on your code, you want to re integrate that chagelist and merge it with yours you can simply unshelf it and resolve conflicts.
So the (other option)
You could do the above with help from another dev with a perforce account (perhaps the one who's changelist you want to ignore) in this case you could have them back out the changelist and submit, then you could sync, then they could back out their back out. In this case the remote branch would not need to stay in weird state while you worked on your code. The big downside is, that you would have to do this every time you wanted to sync.
A better option would be branching before an issue like this arrises but that is not as easy or light weight in perforce as it is in git.
Hope one of these options help or spark a finale and perfect solution from some one else.

Resources