In TFS 2012 (TFVC), how might I rollback a renamed file to the original filename and contents--without having to manually rename the file (?)
Trying to see if possible just using TFS rollback functionality (e.g., tf rollback), not a combination of tf commands or scripted solution.
SITUATION
Four steps: 1) Add a file; 2) Check it in; 3) Rename the file and edit the contents; and 4) Check it in:
Changeset: 2
Items:
rename, edit $/b.txt
Changeset: 2
Items:
delete, source rename $/a.txt
Changeset: 1
Items:
add $/a.txt
I want to rollback to Changeset 1 (a.txt).
WHAT I'VE TRIED
Source Control Explorer Rollback:
In Microsoft Visual Studio 2017 Professional's Source Control Explorer: right-click b.txt > Rollback... > Rollback to a specific version. Specify Changeset 1, then select button Rollback.
This produces the following pending change:
Items:
delete, rollback $/b.txt
Additionally, a warning appears in Output window:
TF203066: The rename from $/a.txt to $/b.txt could not be rolled back
because you did not provide the source name. To roll back the rename,
undo any pending changes to $/b.txt, and then repeat the operation,
but this time include both the source name ($/a.txt) the target name
($/b.txt).
Note: "Rollback to a specific version" doesn't seem to have fields for source and target names.
This seems to indicate rollback doesn't support this scenario (?)
tf.exe Rollback:
Command tf rollback also doesn't seem to have parameters for source and target names:
tf rollback /toversion:VersionSpec ItemSpec [/recursive]
[/lock:none|checkin|checkout] [/version:versionspec]
[/keepmergehistory] [/login:username,[password]] [/noprompt]
When I run the following command, I get the same results as in Visual Studio:
C:\test>tf vc rollback /toversion:C1 "$/b.txt"
delete, rollback:
$/b.txt;C2~C2 -> $/b.txt;C2
as well as the same warning as before:
TF203066: The rename from $/a.txt to
$/b.txt could not be rolled back because you did not provide the
source name. To roll back the rename, undo any pending changes to
$/b.txt, and then repeat the operation, but this time include both the
source name ($/a.txt) the target name ($/b.txt). C:\test>
Note: tf rename has parameters olditem and newitem, which seems to imply warning TF203066 comes from an incomplete call to tf rename.
This seems to imply manual intervention will always be required to rename the file (?)
SOFTWARE VERSIONS
Microsoft Team Foundation Server 2012 CU4 v11.0.61030.0 (TFVC)
Microsoft Visual Studio 2017 Professional 15.9.13
LINKS
Rollback Command (Team Foundation Version Control)
Rename Command (Team Foundation Version Control)
Related
Foll. is my understanding re. TFS rollback.
Assuming I have the foll. scenario:
Changeset
200
199
198
197
196
195
Couple of options to do rollback:
Solution Explorer -> Rt click -> Get specific version, checkout/checkin
Solution Explorer -> View History -> Rt click -> Rollback Entire Changeset
Solution Explorer -> View History -> Rt click-> Rollback selection of changesets
Source Explorer (Visual studio -> View -> Other windows -> Source explorer) -> Rt click file -> Rollback
Option 1 - Solution Explorer -> Get specific version, checkout/checkin: If I want to undo all the changes from changeset 200 to 197 and roll back to what the file was after changset 196 was checked-in, I can use this option - Get specific version (changeset 196) and then checkout and checkin the file.
Option 2 - Solution Explorer -> View History -> Rollback Entire Changeset: This option can be used if you want to rollback that specific changeset. Note that any other file associated with that changeset will also get rolledback. Example if you want to roll back changes made in changeset 197 while still keeping every other following (>197) changeset intact.
Option 3 - Solution Explorer -> View History -> Rollback selection of changesets: Same as option 2, but can be used to roll back multiple changesets. Example to undo changsets 200 to 197 and get the file to what it was when changeset 196 was checked-in
Option 4 - Source Explorer (Visual studio -> View -> Other windows -> Source explorer) -> Rt click file -> Rollback: This brings a dialog box to do either of the foll.:
The first radiobox from below is same as option 2 from above
Second radiobox is same as option 3 from above
Third radiobox is very important and only available from this dialog box which allows us to roll back to specific changeset.
Question: In option 4, do other files from the same changeset get impacted as a result of rollback? Or is this rollback specific to this file only unlike the option 2, 3 counterparts?
Useful Link for Rollback examples
When you right click on a file and Rollback... you got the pop-up, in the top you have the field Items to Rollback, by default the value there will be the server path to the file.
So when you do rollback from there the rollback will be only to this file and not impact other files.
When you click on a file View History and Rollback Entire Changeset all the files of the changset will be rollbacked.
We are trying to have ReSharper's cleanup code run on TFS Checkin. Ideally, when you right click on the solution / project and select Source Control > Check in all the files in the "Included Changes" should run cleanup code. I've got the custom checkin policy to work to some extent, works fine if you select a single file to check in but when you select the solution or project, it tries to run cleanup code on the entire solution / project and not just the files selected in TFS Pending Changes "Include Changes".
I'm running VS 2013 with R# 8.2. My policy evaluate code:
public override PolicyFailure[] Evaluate()
{
if (PendingCheckin.Policies.EvaluationState == PolicyEvaluationState.Unevaluated)
{
DTE2 dte = PendingCheckin.GetService(typeof (DTE)) as DTE2;
foreach (EnvDTE.Document doc in dte.Documents)
{
doc.DTE.ExecuteCommand("ReSharper_SilentCleanupCode");
}
}
return new PolicyFailure[0];
}
I don't think this only applies to ReSharper, executing "Edit.FormatDocument" here would most likely run on all files as well.
Is there a way to run ExecuteCommand on only 1 file / document?
It seems like
PendingCheckin.GetService(typeof (DTE))
only gets files that are open in the Visual Studio editor not all the files that are in the "Include Changes" list. I can get a list of PendingChange through
PendingCheckin.PendingChanges.CheckedPendingChanges
But I don't know how to execute a command on PendingChange. Recommendations here would help
PS: I've read that the check in policy is meant to be used for checking documents only, however this workflow is what we need.
This was easy in VS 2010, but I can't find the right items in VS 2012.
I'd like to set keyboard shortcuts for the Compare With Latest/Workspace Version context menu items in the TFS Pending Changes view. What's the item I should select in the Keyboard section of the Tools dialog?
(This was tested with Visual Studio 2012 Update 1)
Tools > Options > Environment > Keyboard >
Under Show commands containing search and assign key combinations to:
TeamFoundationContextMenus.PendingChangesPageChangestoInclude.TfsContextPendingChangesPageCompareWithPreviousVersion - compares pending item in context to previous version.
TeamFoundationContextMenus.PendingChangesPageChangestoInclude.TfsContextPendingChangesPageCompareWithLatestVersion - compares pending item in context to latest version.
TeamFoundationContextMenus.PendingChangesPageChangestoInclude.TfsContextPendingChangesPageCompareWithWorkspaceVersion - compares pending item in context to workspace version.
File.TfsCompare - open the compare dialog.
For me, this worked:
VS > Tools > Options > Environment > Keyboard > Show Commands Containing: Team.Git.CompareWithUnmodified
By assigning a shortcut key Ctrl+\, Ctrl+\ to this command ( Team.Git.CompareWithUnmodified) I can now compare my current file (the file that is open in the editor) to the previous version of the file by pressing the shortcut key Ctrl+\, Ctrl+\; no need to find the file in solution explorer, then right-click the file then select Compare.
(you can choose your own shortcut key of course)
Just a note on different behaviour:
Team.Git.CompareWithUnmodified works for me because I am using TeamExplorer in VisualStudio but I use GIT as the underlying source code repository.
Tfs.FileCompare could also work in other scenarios (i.e. if you don't use Git, but use VSTS or TFS as your source control provider).
Other: the command will be different if you use another source control provider.
While you have the file open use this combo to compare with Workspace version:
Menu, O, C, Enter
(This performs Right Click > Source Control > Compare > Workspace Version)
If your keyboard doesn't have a Menu key, do this:
Set the hotkey for File.TfsCompare to Ctrl+\ Ctrl+\
Use the combo: Ctrl+[ Ctrl+S Ctrl+\ Ctrl+\ Enter
I am building a VS2010 addin. This addin will work only for our custom project types and create a menu item that will copy the output assembly from the current solution to another solution. Both are under TFS control.
I have the following code:
var tfs = new TeamFoundationServer(address);
var version = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
var workspace = version.GetWorkspace(System.Net.Dns.GetHostName().ToString(), version.AuthorizedUser);
workspace.PendEdit(dest);
System.IO.File.Copy(source, dest, true);
Now I want to checkin the change. The problem is that I don't know how to select only that file I checked out just now? I have other pending changes in the same project and also in other projects. Will this checkin EVERYTHING I have checked out?
Can I be more selective?
PendingChange[] pendingChange = workSpace.GetPendingChanges(dest);
workSpace.CheckIn(pendingChange, comments);
Workspace.GetPendingChanges Method (String)
http://msdn.microsoft.com/en-us/library/bb139277(v=vs.100).aspx
Parameters
item: The path, local or server, to the item that is being queried.
And
Workspace.CheckIn Method
http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.workspace.checkin(v=vs.100).aspx
Parameters
changes
The set of pending changes to check in. If you do not specify this parameter, all changes in the workspace are checked in.
comment
The comment to be associated with this check-in. May be null.
I am trying to setup alerts to the team when a specific file is checked into TFS, have have found some info on this using tfs 2008, which leads me to believe the following filter should work:
'Artifacts/Artifact[starts-with(#ServerItem, $/Matrix/Dev/Matrix/Applications/Matrix.UI/Web.Config)]' <> NULL
But this just give me an Invalid Token error, any ideas how i get this working in 2010?
Thanks.
With installed Power Tools, right-click in Team Explorer on the upmost node (the icon for the TeamCollection) & open "Alerts Explorer".Generate a new CheckIn alert:
now set the source control pathto the files you 're interested in:
This generated a Filter Expression = 'Artifacts/Artifact[starts-with(translate(#ServerItem, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"), "$/foo/bar.cs")]' <> null