Re-do a batch of changes - tfs

I performed the following actions in TFS:
Accidentally made some changes to a bunch of files in the trunk
Realized it.
merged the changes to the intended branch
rolled back the changes in the trunk (using tfpt rollback)
later, during the regularly scheduled forward integration from the trunk, I undid the changes in the branch.
How can I reapply the changes? There are three changesets and about 80 files in question.

A couple ways to do this, but probably the quickest here would be:
Check out the affected files (for edit) in the branch.
Get Specific Version from trunk for those files.
Copy those files to the appropriate branch directory.
Check in.
You could also consider rolling back the rollback changeset in the trunk and redoing what you did (minus the undo).

What I ended up doing was a forced merge:
tf merge /r /force $/source/trunk $/source/branch1 /v:C123~125
I will watch this set of changes carefully when we reverse integrate back into the trunk.
I also tried a tricksy workflow of using tfpt to rollback, shelve, and unshelve /migrate. Unfortunately the conflict resolution dialogue in tfpt unshelve is a bit lacking - missing things like default buttons and stuff, so I had to mouse-click half a dozen times or so per file. So I decided after a few files to try something else first.

Related

TFS getting Branch -> Rollback -> Merge backwards and wanting to erase all changes

We had some changes committed (let's call it changeset1) in what we call the Dev branch of our project that really should've been done in a new branch. So what I did to fix it is create a new branch off of the Dev branch (let's call it Dev2). Then I rolled back the Dev branch to before changeset1. So now the code base looks like the development was done in Dev2 and Dev was never touched.
Later, I then did some development in Dev, merged it to Stage, and then Prod. Now I'm trying to also merge those changes into Dev2 but when I perform the merge (in VS 2017) it auto-merges everything and it wants to delete all of the changes from changeset1. I guess because I rolled back Dev after changeset1, it sees that as the latest change and wants to merge that rollback to Dev2. How can I get it to see Dev2 as the latest and merge my new Dev changes into it without deleting changeset1's changes?
For clarification, Dev is the parent of both the Stage and Dev2 branches.
According to your description, seems the merge process didn't pick up the rollback changeset1 in Dev branch, which cause this scenario.
This is caused you didn't use /keepmergehistory option during your rollback.
tf rollback /keepmergehistory
This option has an effect only if one or more of the changesets that
you are rolling back include a branch or merge change. Specify this
option if you want future merges between the same source and the same
target to exclude the changes that you are rolling back.
Please go through the detail explanation and some examples in our official tutorial here: Example: /keepmergehistory Option
Besides, you could also take a look at this similar question: TFS merge doesn't pick up rollback changeset(s)
I figured out a way to resolve it. So to re-iterate, I think the problem was the changes I wanted were in Dev2, but I rolled back Dev after creating Dev2 so the rollback was the most recent change so the merge wanted to keep the rollback and delete the changes I wanted to keep from Dev2. So I came to the conclusion that what I need to do was somehow apply those changes to Dev2 again as if they were a new edit.
So what I did is:
Move the changes from changeset1 into a Shelveset
Merge Dev to Dev2, thereby deleting the desired changes
Unshelve the changeset1 Shelveset to Dev2
#1 was the hardest part. First I created two new workspaces: DevC0 and DevC1. I pulled the changeset from before changeset1 into DevC0 and pulled changeset1 into DevC1. So now DevC1 has all the changes I'm interested in and DevC0 does not. I then copied all of the changed files (using BeyondCompare but I think you could just copy all your files except for the TFS folders/files too) from DevC1 to DevC0. Then at the command line, I did a tf vc reconcile on the DevC0 folder to allow it to recognize all the changes I just copied over. E.G. (I didn't actually want /deletes in my case):
tf vc /reconcile /promote /adds /deletes /diff /recursive [DevC0 itemspec]
(Make sure your command prompt's working directory is a directory mapped to your target workspace). After that, all of the differences now appear as pending changes in Visual Studio Team Explorer/Source Control Explorer. So from there I can create a Shelveset.
#2 was just a typical merge from Dev to Dev2. It deleted all of the changes and made Dev2 match Dev. I don't know if I needed to check this in before applying the Shelveset but I did.
#3 My changeset1 changes are in my Shelveset, but the Shelveset belongs to the Dev branch. Luckily, Team Foundation Power Tools can unshelve a Shelveset to a different branch. E.G:
tfpt unshelve /migrate /source:"[Dev server path]" /target:"[Dev2 server path]"
This opened a window with merge options for each file. I manually reviewed the first few then tried auto-merging all. That did the equivalent of what merging via Visual Studio does - it auto merged where possible and left the conflicts up to me in that same window. After that, it appeared all of the desired changes were now pending changes in Dev2 and I checked them in.
I then tried a merge from Dev2 back to Dev just to see if it was going to behave correctly and it did merge all of the changes to Dev and marked many of the changes that were deleted by the original rollback as undeleted. For now, I undid pending changes from that merge until we are actually ready to merge this sub-branch of work into our main Dev branch.

Apply a changeset to a branch when directory has been renamed

I have made some changes in a branch which involve renaming the sub-dir a project's code files live in, and committed this branch. I was unaware that while I was working on my branch, another developer made changes to one of the source files in this sub-directory and committed this.
When I merged my branch, it didn't detect the other developer's changes and undid them silently, which we only found later. When I try to re-apply their changeset, it just restores the files in their previous location.
I can manually re-apply their changes since it's an isolated case, but is there actually a way I can apply a changeset in this scenario, tell TFS the two directories are equivalent or something?
In your scenario, you can use tf merge command from command line with /recursive keyword, as since there is no way to specify the old name of the source branch from the UI, but we can from the TF merge command line.

TFS: Undo checkout from "merge, branch, edit" to "merge, branch"

I have following situation:
I have created some new projects in solution in one development branch in TFS
I'm now merging them into the main branch.
Architect has idea to merge two new modules into one.
I have moved the code files
Project files has already been changed within the merge.
These files have pending changes in form merge, branch, edit. I wan't to make this file merge, branch, delete but TFS won't do that because the file has pending changes. Is it possible to force the deletion or undo edit without undoing merge, branch?
I don't want to try the merge again and combine files from two shelvesets... Is there any possibility to modify the status of pending changes?
No, TFS does not support that.
You could "undo" the file and just pend a delete instead.
As best practice you shouldn't be making changes as part of a merge, you should just do the minimum possible to resolve the conflicts and get it to build (or not even that sometimes) and then make your required changes in a subsequent check-in. This makes it easier to see in the version control history what changes were made when - I very rarely look to see if a merge of a change is any different from a prior edit.

TFS reverse integration back to main

I have the Development branch forked from the Main branch.
Could I merge the Development branch back to the Main so that Main branch code would be equal the Development branch?
What is the most safe and reliable solution for this?
The easiest way I've found to do this is to do a merge using Visual Studio and the Source Control Explorer.
In the Source Control Explorer, right-click on your development branch and select Branching and Merging > Merge
In the Target Branch drop-down select your trunk ("Main") as the destination. This is likely the default selection if you've branched from Main originally.
There are two options:
All changes up to a specific versions: You choose based on a revision and merge it all up to that revision in one fell swoop. If you have a lot of changes, this can save you some time, but also is riskier in terms of resolving conflicts if there have been a lot of changes in Main.
Selected changesets: You select single or groups of changesets to merge back and then repeat this process until you've merged back what you need. Less risky option, but much more time consuming. I personally prefer this approach so that I can see the changes going back into the trunk and know what to expect as changes.
TFS will instruct you if there are merge conflicts while you are merging. This occurs when you change something in the trunk after you've branched to your development. If one of the changes you've made in development conflict with the changes you've made in the trunk, you will have the chance to resolve this in Visual Studio.
If you do not have any conflicts, your development changes will move into the Trunk and simply merge with the changes you already have there.
I admit one work place they merged the Trunk to the Branches, but its not supposed to work that way.
The generally accepted method is merge the Branch back into the Trunk.
It sounds like you are working in the Trunk ("I can create some additional folder or additional files in the trunk") and wanting to merge into the Branch.
I recommend doing it the standard way: only work in Branches merging back to the Trunk, never coding directly in the Trunk.

TFS / Merging a missed check in

Yes this is one of the Doh! Damn! I shot myself in the foot. I don't have a lot of experience with TFS in large teams, but I'm facing this issue.
During a transition to new equipment, a developer forgot to check-in some code. Work proceeded on the new laptop for several weeks before noticing that the previous work was not checked in. Mutliple check-in have occured.
I have recovered the files from the old laptop, and have them on my current laptop. What is the best way to merge in these changes? Do I create a branch, merge in these changes, and then rejoin the branch?
Is there a "cookbook" out there that details what should happen when faced with various situations?
We are using TFS 2010.
Thanks in advance...
Creating a branch here is probably a little bit heavier-weight than what you need for this one-off situation. If it were me, I would do this:
Set up a workspace on your computer with the appropriate mappings.
Do a Get Specific Version to the version that the other computer was at. The best case scenario is if the user never deleted their workspace on the server. Then you can simply specify their workspace as the version and you'll get the files as they existed on the laptop. (You can specify this as Wworkspacename;owner name.) If the user deleted their workspace, you can get based on the changeset number they were at, or based on the date they were working at.
Copy the recovered files on top of the new TFS workspace.
Run tfpt online from the Team Foundation Server Power Tools. This will examine the local filesystem against the server and determine what changes were made. You may wish to examine the options, notably the /diff flags (which performs MD5s on the file instead of simply examining the readonly bit), and the /deletes and /adds flags, which detect deleted and add files, respectively.
Do a Get Latest on your workspace, resolve any conflicts, and check in.
You can follow this sequence to try out:
Make a merge-branch of your code version based on the time-stamp of where your restored laptop code has left the version control system.
Get your branched code to a location on disk.
Perform a check-out for edit of the entire workspace.
Copy the old restored code over the files in this workspace.
Perform a checkin of the local code into the branch.
Merge your latest code (main trunk) into the branch, merging changes, solving conflicts.
If all build and tests out correctly on the merge branch, merge that branch back into the main.
That should do the job.

Resources