TFS - Is it possible to rollback a changeset committed before the branching?
Suppose I Branch Solution-A, changeset 10 into Solution-B.
Later on, I realize Solution-B should not have changeset 7 in it.
Is t开发者_StackOverflow社区here a way to rollback changeset 7 just from Solution B without harming solution A?
Whenever I use tf rollback, all the pending changes go to Solution-A.
Thanks in advance !
I know this is an old question, but this may help anybody who has the same problem. Especially when you need to rollback a changeset, which was checked in long ago on another branch.
Update WORKSPACE_ROOT and TFS_BRANCH_ROOT in the following batch file. Name it e.g. RollbackMigrate.cmd and run it always from the workspace root.
This batch file will:
- Parse arguments - only one argument is the change set number
- Find the name of current workspace and it's path on TFS
- Find the TFS source path for migration
- Map the source into current workspace
- Rollback the change set
- Create shelve set and undo check out
- Remove the temporary mapping
- Unshelve the previously created shelve set and migrate it
- you just need to auto merge the shelveset in a new window
- Delete the temporary shelve set
- Checkin
- you just need to update the comment, notes and work item link
@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set WORKSPACE_ROOT=D:\PathToMyWorkspaces
set TFS_BRANCH_ROOT=$/Project/Branches
:01_ARGUMENT_PARSING
echo Rollback changes from another branch
if [%1]==[] (
set /P CHANGESET=Enter changeset number:
if [!CHANGESET!]==[] (
echo Changeset number is required! Exiting!
exit /B 1
)
) else (
set CHANGESET=%1
shift
)
set SHELVE_NAME="Auto shelved rollback of %CHANGESET%"
:02_FIND_MY_WORKSPACE_NAME
for %%i in (.) do (
set WORKSPACE=%%~nxi
)
if not [%CD%]==[%WORKSPACE_ROOT%\%WORKSPACE%] (
echo This script works only in the root of workspace e.g. D:\PathToMyWorkspaces\MyWorkspace
exit /B 1
)
echo Current workspace is %WORKSPACE%
for /f %%i in ('tf workspaces %WORKSPACE% /noprompt /format:detailed ^| grep -om 1 "$/[^:]\+"') do (
if not [%DST%]==[] (
echo Cannot work on workspaces with more mappings! Exiting!
exit /B 2
)
set DST=%%i
echo Found destination path for migration: "%%i"
)
:03_VIEW_CHANGESET
for /f %%i in ('tf changeset 1570888 ^| grep -om 1 "%TFS_BRANCH_ROOT%/[^/]\+/[^/]\+"') do (
set SRC=%%i
echo Found source path for migration: "%%i"
)
if [%SRC%]==[] (
echo Cannot find path to source branch! Exiting!
exit /B 3
)
for %%i in (%SRC%) do (
set SRC_BRANCH=%%~nxi
)
:04_MAP_SOURCE
set TMP_SRC_PATH=%WORKSPACE_ROOT%\%WORKSPACE%_%SRC_BRANCH%
echo Create temporary mapping for source branch in %TMP_SRC_PATH%
mkdir %TMP_SRC_PATH%
echo Creating mapping for "%SRC%" to "%TMP_SRC_PATH%"
tf workfold /map %SRC% %TMP_SRC_PATH%
if %errorlevel% NEQ 0 (
echo Can't create mapping for "%SRC%", exiting!
exit /B 4
)
:05_ROLLBACK_CHANGESET
echo Performing rollback of changeset %CHANGESET%
tf rollback /changeset:%CHANGESET% /lock:checkin /keepmergehistory
:06_SHELVE_ROLLBACK
echo Shelving rollback
tf shelve /comment:%SHELVE_NAME% %SHELVE_NAME% /noprompt /move /replace
:07_UNMAP_AND_DELETE_TEMPORARY
echo Unmapping "%SRC%" from "%TMP_SRC_PATH%"
tf workfold /unmap "%TMP_SRC_PATH%"
echo Deleting "%TMP_SRC_PATH%"
rmdir /S /Q "%TMP_SRC_PATH%"
:08_UNSHELVE_MIGRATE
echo Unshelving the rollback...
tfpt unshelve /migrate /source:"%SRC%" /target:"%DST%" %SHELVE_NAME% /noprompt
:09_DELETE_THE_SHELVESET
echo Deleting the shelveset
tf shelve /delete %SHELVE_NAME% /noprompt
:10_CHECKIN
echo Checking in the rollback...
tf checkin
You have to rollback the changeset that has the merges to solution b, and then reapply the merge without changeset 7.
I recommend using the TFPT.exe which comes with the power tools pack: http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f/
High level overview:
- From the workspace mapping of Solution-B rollback the changeset
- Commit the change for the workspace mapping in Solution-B
Commands:
- c:\workspace\mapping\to\solution\b> tfpt rollback /changeset:7
- c:\workspace\mapping\to\solution\b> tf commit
Finally I did something like below.
- Rollback changeset 7 on Solution-A and checkin. This will create changeset 11 on Solution-A
- Merge the changeset 11 to Solution-B branch
- Rollback changes 11 on Solution-A branch and checkin which will create changeset 12 on Solution-A
In future merges to Solution-B from Solution-A skip merging changeset 12.
精彩评论