How to move pending code changes from one branch to another in TFS.
Pre-requisites:-
Make sure you’ve TFS power tools installed in your system. If not, you may download it from below links according to your TFS version
Scenario:-
Ever wondered how to move your pending code changes from one branch to another without manually replicating the changes? Let’s say you have a team project within which there are 3 branches (Main, Branch-v1 and Branch v2) as shown below. You’ve done a lot of code changes in Branch-v1, and now your requirement specification doesn’t allow you to commit the code in the same branch, instead your code is required to be checked-In in Branch-v2. Since the number of changes is high you would certainly want some automated approach to moving your changes to branch-v2 efficiently and accurately without performing a bunch of manual copy-paste operations. So to ease up your work you may follow the below steps.
Steps:-
- Create a shelve set of all your pending changes.
- Undo all changes on the current branch (Branch-v1) and ensure there are no pending changes left. (This is important to bypass undetermined workspace error). You may take a physical copy of your code if you’re afraid of losing it.
- Start Visual Studio Command Prompt.
- Set the path using “cd” command to the folder where target branch (Branch-v2) is mapped to.
- Type the below command with appropriate values and hit enter.
Usage:
tfpt unshelve [shelvesetname] [/source:serverpath] [/target:serverpath] [/migrate]
Example:
1 2 3 |
D:\Project1\targetBranchName>C:\"Program Files (x86)"\"Microso ft Team Foundation Server 2013 Power Tools"\tfpt unshelve "My Changes” /source:"$/myteamproject/sourcebranchName" /target:"$/myteamproject/targetbranchName" /migrate |
- Shelveset details window appears, check the relevant files and click Unshelve.
- Conflict window appears, click Auto-merge all or you may resolve it manually as well.
- Once all conflicts are resolved, click Close.
- Open the target branch solution in Visual Studio and verify merged changes.
Known issues:-
-
tfpt is not a recognized command
- Make sure to use the absolute path to the utility i.e. C:\”Program Files (x86)”\”Microsoft Team Foundation Server 2013 Power Tools”\tfpt
- Ensure there is no typo in the command “tfpt”
-
Unable to determine workspace
- Double check to set the initial path using “cd” command to the folder where target branch resides.
- Take the latest from your source control for both branches.
Please note branches can be spread across different team projects as well.