How come my merged changesets are reappearing when doing reverse integration? - tfs

Maybe its a confusing title but the scenario is this one - we have two branches; DEV -> QA. When tests are done people merge their changesets from DEV into QA one by one. All fine. The strange thing is that a small number of merged changesets are appearing in Merge wizard when we attempt to do reverse integration QA -> DEV. If I pick one for the merge, pending change shows that files are checked out with an 'merge,edit' tag but when compared to latest there are no differences.
Obviously we need to fix this since the list keeps getting longer and longer. But, I would like to understand why is this happening in the first place. Then, how to fix this situation.
We're using TFS 2015 server and Visual Studio 2015. No 3rd party tools.
Thank you for reading.

When you want to merge back, the changeset reappears is because when TFS does a merge, it bases the merge on prior merge history, not on the actual contents of the source and target files.
If you have such request, you can use tf merge /discard command to update the merge history, which does not perform the merge operation. This discards a changeset from being used for a particular merge.
https://learn.microsoft.com/en-us/azure/devops/repos/tfvc/merge-command?view=azure-devops

Related

HowTo: correctly synchronize TFS branches with missing changesets?

Background
If I merge our main branch to our development branch, TFS will state that there are no changes to commit. And yet, a file level comparison (using WinMerge) clearly shows that there are differences (e.g. files missing, files with different content, etc.).
In short, our main and development branches are no longer in sync which is most likely due to changesets that were lost during previous TFS migrations.
Question
What is the best way to produce the following?
Synchronizing the main and development branches by: performing all of the necessary insert/update/delete operations on the development branch. (i.e. main is the master copy).
At the end of the process WinMerge should indicate that there are zero (0) differences between the two branches.
Keeping the development branch history intact.
Notifying TFS that the development branch is now fully synchronized with main so that:
TFS won't try to merge older development changesets with main
only future changes to development will be pushed to main during a merge operation.
TFS is not my area of expertise - any guidance that you can provide would be greatly appreciated.
Context
Visual Studio 2015
TFS (version 14.95.25122)
References
Merge Command
"Performs a merge without a base version. That is, allows the user to merge files and folders that do not have a merge relationship. After a baseless merge, a merge relationship exists, and future merges do not have to be baseless."
Although Development was branched from Main, it looks like this might address my lack of history (i.e. missing changesets) problem.
TFS Merge: Best Practices
TFS: Overwrite a branch with another
tf merge A B -r -force -version:T
I don't think this will work for us because changesets are missing.
When TFS does a merge, it bases the merge on prior merge history, not on the actual contents of the source and target files.
This issue may by caused by picking keep target when perform merge or at one time, a merge with the discard option performed (using the command line TF merge /discard).
To solve this issue, you can try to:
Use the /force option with the tf merge command. If there is a changeset that was previously merged (perhaps incorrectly) and you want to merge it again. The /force flag ignores merge history that indicates a particular changeset was previously merged from source to target, and merges the changeset again.
Undo the previous merge using Rollback. If you've recently done the merge in which changesets have been discarded. Find it in the history, rightclick the changeset and pick Rollback and check in the code that has been undone.

Merging with TFS 2012 is trying to take across changes that have already been merged

We have a branch called "Main". In July 2012 I created a new branch from this called "Phase 3" for the next version of our project. We have been working on this since then, but from time to time some other changes get applied to Main.
In May this year we performed a merge from Main to Phase 3 with some of those changes, and that was all fine.
Between then and now, we upgraded our TFS server from 2008 to 2012 update 3. (I wasn't involved with the "upgrade" but I believe it was an install on a new server with some kind of backup/restore of the data.) We've bit had any other issues with this.
Last week I tried to perform another merge from Main to Phase 3. I chose "selected changesets" because we have done a serious amount of rework in our phase 3 branch so merging changes across is quite difficult - so I wanted to do them bit by bit.
However, I was surprised to see that Visual Studio was trying to merge across changes from July 2011 - a good year before the branch was made (the very first changes made to this part of our project in fact.)
Oddly enough, if I view the history of the phase 3 solution I can expand it and see all these changes. So TFS appears to know that they have already applied.
I tried to merge some of the earlier changes across to see what would happened. The only changes it included were to do with items that had been renamed or deleted. For example, we had renamed our solution so TFS wanted to branch and merge a copy of the SLN with the old name. Or we had some images that had been subsequently deleted in both branches, but not at the time of this new merge.
So I backed this out and tried to merge everything across from May this year - i.e. just before our last merge across. This carried over a hideous number of changes - all sorts of things including regular merge/edit type changes. So I backed that out too!
We had created another branch from Phase 3. I have been able to merge between the two branches OK. I think it was created about a week before the TFS upgrade. But it's not experiencing the issue.
We have other branches that were taken from Main. These are experiencing the issue in that TFS is wanting to apply changes that it has already made.
I am using VS2012 update 3 to do the merge. I also tried VS2010 just in case but that does the same. Also a colleague has tried it and confirmed the same symptoms.
I don't think it helps that our phase 3 is so vastly different to main that merging anything across is really difficult.
Does anyone know how I can best resolve this? I'm a little worried about doing something I might regret later on!
I encountered similar problems when upgrading from TFS 2008 to TFS 2010. The issue is probably due to partially merged changesets. I.e. some of the files in the changeset have been merged, some haven't. Or it could be a branch move / rename situation. See the answer here for details of why a branch rename can cause this problem
In TFS 2008 if you attempted a merge, then unchecked files from the pending changes list. TFS assumed that you didn't want to merge the file ever again and on subsequent merges you wouldn't see those files.
In TFS 2010 or higher, the behaviour changes. If you uncheck files from the pending changes, on the next merge TFS will attempt to merge those files again. I think TFS 201x has the correct behaviour but its a pain that MS didn't highlight the change in behavior.
To check if this is the case, run the following from the command line
tf merge $/tp/main $/tp/phase3 /recursive /candidate
The /candidate switch tells TFS to give you a list of changesets it wants to merge without performing the merge. If you see any changesets in the list that have a * next to them, these are partially merged.
To fix it you have 2 choices.
Merge the files and resolve the conflicts, it might be worth merging on a changeset by changeset basis rather than trying to do them all at once. This will probably be a bit painful but once it's done it's done.
If you're confident that the phase 3 branch is correct then you can Merge using the command prompt. If you use tf merge $/tp/main $/tp/phase3 /version:c123~c456 /recursive /discard where c123 represents the oldest changeset you want to ignore and c456 represents the most recent changeset you want to ignore. The /discard switch tells TFS to update the merge history so that it thinks the merge has been done, but it won't actually perform the merge. This should remove the partially merged changesets from your list of candidates
If you opt for option 2 then you should do some analysis to make sure that you really don't want to take the partially merged changesets.
If you get to the point where merging is too difficult, or you just don't trust it.. then the only practical option is the "stomp over it with a new changeset". ie - do the merge manually outside of TFS and then commit your new, fixed changeset. then, kill the old branch and start again.
Not an ideal situation to be in, but your source integrity is paramount. Hopefully starting from a fresh branch will prevent issues like this in the future.

TFS move a changset forward in the same branch

We currently have up to 3 developers working in the same branch.
In Jan, I submitted changesets (say 100-110) that have since had some code overwritten by changsets (111-300) during merges from other team members. I'm now just getting back to my project and I dread having to manually re-type all that code.
I can identify the exact changesets I need.
Is it possible to "merge" these specific changesets into the latest version of the same branch?
You can merge the changes in the same branch.
GO TO Branching and Merging option and click on the merging option you can merge the changes by choosing change set, date or label.
Hope you get my words

TFS 2010: Branching - Why do changesets say they haven't been merged when they were from before the Branch?

I made a branch and the first time I went to merge from the source to the branch there were a whole bunch of old changesets coming up that it says were not merged but they were present well before the branch and I confirm that they were there.
Example:
Say I branched from Source to Target when there were 9 changesets in Source.
Change 10 was made in Source.
I go to merge from Source to Target and TFS tells me change 6 and 7 and 10 need to be merged (even though 6 and 7 were there before I branched and I can confirm those changes are in the Target)
I am new to TFS and this happened when I first started to implement Branching and Merging.
The newest branch I made did not do this.
Right now we have a Trunk and then 1 Branch for the ongoing QA for the next release and another Branch for the Hotfixes to Production. It was the QA branch that had this issue but when I made the hotfix branch it was fine.
I have come across this a few times. I eventually just merged the "rogue" candidate change-sets from source to target. I examined the pending merge and determined that there were no changes. Committing the merge got rid of these candidate change-sets. I figured that I could roll back if it didn't work out.
EDIT: It appears that if you upgraded to TFS 2010, there is a bug that will cause extra merge candidates (see http://support.microsoft.com/kb/2135068)
"Any items on a branch that have been renamed multiple times or have had multiple other items occupy their namespace (through add/delete combinations) will have lost their relationships with the corresponding items on other branches."
As for a resolution, the support article says:
"To resolve the issue with extra merge candidates, the /discard option should be used. To do this, run a merge of the following format from a command line:
tf merge <source branch> <target branch> /r /discard:CXXX~CYYY
In this example, XXX and YYY represent the changeset IDs of the range of changes to discard. After this merge has been checked in, the unwanted candidates will no longer appear for future merges. Also be aware that, because of improvements in the merge algorithm in TFS 2010, items deleted in both the source and target branches will result in changes to be merged. In those cases, it is best not to discard the changesets so that the merge history is updated correctly. "
I've had this a few times too. I suspect the cause is some funnyness in the way TFS manages pending merges. If you try to merge these changes, and the Change type is just "merge" and not "merge, edit", then it is safe to merge them and be confident that no changes have occurred. If you don't merge them, TFS will keep trying to merge the non-changes indefinitely, possibly obscuring real changes eventually. I advise merging these non-changes ASAP.

TFS: multiple merge operations on same file

Imagine the following situation: I have two branches: DEV and MAIN. I'm working on a file in the DEV branch called program.cs. I checked it in multiple times, so I end up having a couple of changesets: for example 5900, 5905, 5909. Please note these are not contiguous.
Now I want to merge these changes to MAIN, but without checking in each changeset in between. This isn't possible because: the first merge works, but the second merge of the changeset gives me the following error:
TF14085: Cannot merge $/DEV/program.cs to $/MAIN/program.cs because there is an incompatible pending change (not edit or encoding) at $/MAIN/program.cs already.
Is there any way to get around this error? Is Visual Studio 2010 behaving the same (I will probably have the chance to try this out later today)? How does TFS do this when merging multiple, but contiguous changesets?
You need to check in the current changes then redo the merge. I have had the same issue and unfortunately the only way around is to check-in between merges.

Resources