Can I unshelve to a different branch in tfs 2008?
Asked Answered
J

5

105

Let's assume that some developer in my team shelved his changes that he did in branch A. And I am working on branch B. Can I unshelve his changes into branch B? (By GUI or command prompt)

Juju answered 22/9, 2008 at 20:19 Comment(1)
Demo of above command: Unshelve command basicsProboscidean
Q
129

The Visual Studio Power Tools should let you do this.

C:\src\2\Merlin\Main>tfpt unshelve /?
tfpt unshelve - Unshelve into workspace with pending changes

Allows a shelveset to be unshelved into a workspace with pending changes.
Merges content between local and shelved changes. Allows migration of shelved
changes from one branch into another by rewriting server paths.

Usage: tfpt unshelve [shelvesetname[;username]] [/nobackup]
                     [/migrate /source:serverpath /target:serverpath]

 shelvesetname          The name of the shelveset to unshelve
 /nobackup              Skip the creation of a backup shelveset
 /migrate               Rewrite the server paths of the shelved items
                        (for example to unshelve into another branch)
 /source:serverpath     Source location for path rewrite (supply with /migrate)
 /target:serverpath     Target location for path rewrite (supply with /migrate)
 /nobackup              Skip the creation of a backup shelveset

For example to merge a shelve set called "Shelve Set Name" created on Branch1 to Branch2 use this:

>tfpt unshelve "Shelve Set Name";domain\userName /migrate /source:"$/Project/Branch1/" /target:"$/Project/Branch2/"
Quirinal answered 22/9, 2008 at 20:24 Comment(8)
Ooohhh... Curt, I think you just made my day. I'm going to have to try that later.Ornelas
Where do you get the power tools from?Achromatic
Yep, the power tools SHOULD let you do this, but unfortunately the merge goes horribly wrong each time so it's next to useless.Kial
The merge isn't that bad. I found that Auto Merge works in 90% of the cases.Kami
The power tools can be freely downloaded from some MSDN site. Use Google or Bing to find the right site -- that's what I need to do, too.Quirinal
@apathetic - Masterful. :) Um, 'auto merge'? Yeah, cause that's what I want to do, trust a tool to decide conflicts for me. :) If that's what you mean by 'the merge goes horribly wrong', it's time to spend a bit more than 30 seconds recovering your shelfsets. :) Much better than copying the files over and having No Idea wtf the changes were. :)Sonja
Just tried it. I moved many files within the shelfset and unfortunately this doesn't seem to work well . You need to manually "migrate" all these files (there is also no multi-select). And then they are added as new files to the workspace. I can't use it, because I can't merge it anymore.Servomotor
@user254180 - "Um, 'auto merge'? Yeah, cause that's what I want to do, trust a tool to decide conflicts for me" - Automerge merges the changes automatically that do not conflict. When they do conflict, you are being asked to resolve them manually. That's the beauty of it.Mediatory
R
34

Alternative solution to tfpt that avoids having to merge each file manually

The problem with the tfs power tool is that you're doing a 'baseless merge' so have to confirm every file. I had a shelveset of over 800 files and I never trust the 'auto merge' button and didn't want to go through each file in turn - so I had to find another way!

  • Download and install the TFS Shelveset Sidekick.
  • The tool appears under 'Tools' in VS2010
  • Run the 'Shelveset Sidekick' tool, click Search to show shelvesets
  • Right click on your shelveset and select 'Export Shelveset'
  • Save to an empty location such as C:\temp\shelveset-name
  • Now have a complete directory structure containing JUST the new files

(Note: There's no progress bar when exporting - so if you have a large shelveset that takes a long time to export you'll just have to check in Windows Explorer (File>Properties>Size) that the files are still coming down if you think it's frozen).

You now just have to copy them over to the new branch with Windows Explorer.

This worked for me :

  • Checking out the whole solution first (in the new branch)
  • Close that solution
  • Take TFS offline from within VS (Tool to do this) - see below for why this is important...
  • Copy files over in Windows Explorer. The directory structure in c:\temp\shelveset-name will have to be renamed to correspond to the new branch. Tip: Make sure you copy to the right place!!!
  • Bring VS online
  • It should find all the changes and add the new files
  • If it asks you to bind the sourcecontrol be sure to verify the path is correct for the new branch.
  • Test - and then checkin the new files

Important: I've found that if you don't first take TFS offline then you'll end up with any new files (from your unshelves changeset) showing without a little red check mark and you'll have to exclude and include them again to get them to add. If anyone has an alternative solution to this problem I'd love to know - refreshing doesn't seem to work.

Rig answered 25/3, 2011 at 5:22 Comment(7)
This method is easier for larger shelvesets and is the one I followed. Thanks!Rorie
This method is really better for bigger shelvesetsMature
Well you may get away without taking TFS offline. But I am not sure it is worth it. What I did was to run the Compare action - in Source Control Explorer from the context menu open on the relevant folder. One can filter the output to only show the items that are different. Then it allows to do a multiple selection on them and Check Out all of them at once. But I guess taking TFS offline is faster and simpler than that.Geyer
Unfortunately, this does not work for me when I have "add" changes in the shelveset. I get an error "Failed to retrieve shelved file.A shelved pending change on a file is required".Raimes
@JohnSaunders you mean a shelveset with any adds or exclusively adds? I haven't needed to do this in years :)Rig
A shelveset with many adds. I made a number of changes in the wrong branch (and on a different computer) and wanted to move them to the correct branch on my new computer.Raimes
My situation was kind of a one time thing. I don't have any branches, just need to do this kind of stuff occasionally when I have a fried laptop and need to get files onto my spare. Good luck tho :)Rig
O
1

The shelf information includes the specific path it goes to. Unfortunately I don't know of any automatic way to unshelve to any location other than the one it was shelved to. The times I've wanted to do this I had to check out the equivalent files in the new branch, unshelve from the old branch, then manually copy the files over.

EDIT: Well, I guess I was doing it the hard way. I'll have to try out Curt's solution. :)

Ornelas answered 22/9, 2008 at 20:23 Comment(0)
J
0

I spent good amount of time to get this done and I had few issues to overcome. It is possible but here few issues and few rules to follow to avois these issues

Error:

unable to determine the workspace

This particular issue was solved by running the command from source branch root folder. This is contrary to some answers on SO where they say to use "target" branch - no, use "source":

cd [your !!source!! branch root]
tfpt unshelve /migrate /source:"$/MyCollection/Development/Maint1.1" /target:"$/MyCollection/Development/Maint1.2" "myShelveset;UserName"

Second issue appeared after this. Seem that it couldn't connect to TFS server. What I realized, I have multiple VS installed and connected to different TFS servers. I was using VS12 and I had workspace and server connection. But I didn't realize that same connection needs to be replicated in VS13 for TFPT2013 to work. It connects to same server and workspace.

I also tried doing it using TFPT2015 but I installed it and it didn't install TFPT.exe hence it was useless. So I tried from TFPT2013 to TFS2015 and it worked for this particular command. I wonder, why not, if VS12/13 works fine against TFS2015?

To summarize

  • Use CMD or DevCMD - doesn't matter
  • run command from source branch root folder
  • verify Team Explorer Server connection for specific VS
  • TF Power Tools 2013 work against TFS v15, at least migrate option works
Joellyn answered 9/5, 2018 at 19:7 Comment(0)
I
0

The following steps can be used for small size shelvesets (~20 files or less).

  1. On the shelveset and target branches, start by having all pending updates checked in or rolled back.
  2. On the shelveset branch, unshelve the files from the applicable shelveset.
  3. On the target branch, checkout any of the existing files that were in the unshelved shelveset.
  4. Compare the unshelved files on the shelveset branch with those on the target branch to identify those files that require merge updates (if any).
  5. If needed, manually make merge updates to the applicable files of the prior step and save these files in the target branch workspace.
  6. Copy the other shelveset files from the shelveset branch workspace to the target branch workspace.
  7. Compare the new updated files in the target branch workspace with the checked in files. Make any corrections as needed.
  8. Check in the new updated files on the target branch.
  9. Rollback the unhelved files on the shelveset branch.
Isosceles answered 9/9, 2019 at 14:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.