tf.exe undo pending changes from other users - tfs

I am looking to migrate our TFS projects to another server. Before doing this I want to inspect all pending changes, undo them (or tell the person that has it checked out what it's all about) and lock the project on the old server.
For this I need to undo checkouts in very old workspaces that no longer exist. I'm now looking for ways to make this work. I realise there are a bunch of other questions like this, most with answers that point towards using tf.exe, which I am also using, but there's one thing that I just can't seem to get my head around.
Here's the deal. I'm using the following command to check to see if there's still files checked out by anyone.
tf status "$/MyProject" /s:MyServer /u:* /recursive
This presents me with a list of all files that are checked out and by whom. To undo the checkout I can now use this command:
tf undo /workspace:"TheWorkspace";TheUser
$/MyProject" /server:MyServer /recursive
This is all very nice, but notice how I need the workspace name to make this work. This name is however not returned by the tf status command. So now I'm forced to mess around with the workspaces command to figure out which workspaces a user has like this:
tf workspaces /server:MyServer /owner:TheUser /format:detailed
There has to be another way right? This way I'm just looking through a massive report on workspaces for each user (some have had as many as 6 computers/laptops over the years, all with dozens of workspaces), it's no fun :(
Is there any way to make tf status report the workspace name as well? Or make the undo command work across workspaces?
Any help would be appreciated.

tf status supports a /format parameter. The brief output (which is the default) doesn't include the workspace. the detailed one does.
tf status "$/MyProject" /s:MyServer /u:* /recursive /format:detailed

Related

Checkin multiple files with tf.exe in one changeset

On one of our builds we are kicking off some automated process which is checking out and checking in some files automatically.
This all works rather well, but at this time we are running the checkin command which looks like the following
tf.exe checkin /force /comment:"foo" /noprompt /bypass /override:"bar"
All of the files with a Pending status will get checked in.
I'd like to make this script a bit more specific and only checkin the files (2 in total) which we actually change during the build, so we know for sure no files will get checked in 'by accident'.
I've already seen we can specify a single filename with the checkin command, but doing so we will get 2 different changesets in TFS, instead of 1. We would really like to have 1 changeset, containing both changed files as the changes belong to eachother.
Any ideas on how to approach this?
Minor addition / Short term solution
For the moment I've solved our 'problem' by specifying the folder where our modified files are located, which kind of looks like this
tf.exe checkin "/my/folder/location/" /recurse /force /comment:"foo" /noprompt /bypass /override:"bar"
Note the folder location and the /recurse parameter added.
You simply separate the files by spaces:
tf.exe checkin file1.ext file2.ext /force /Comment:"foo" /noprompt /bypass /override:"bar"
The documentation is not clear about this point but it might be a general specification of an itemspec that it can be multiple items.
See similar question about checkout: Is there a way to check-out multiple files from various folders in TFS in a single operation
As mentioned by others you might run into problems with the command line being longer than the system supports, in which case you might need to look at other solutions.
cmd.exe has a limit on how long a command can be. Using the version control API, or simply 'tf checkin /i' (no arguments) is likely to be a better choice than passing lots of long filenames.
It's normal if a file becomes automatically checked out due to a change, and if ultimately the contents of the file are changed back to it's original state. At that point you would see the message about identical contents upon comparison. You could also use tfpt uu /noget /r * command to ignore Files which are identical to the originals. You'll need to have TFS Power Tools installed for this to work. Note: there is no TFS Power tool 2017.
For more details please refer below two links:
Visual Studio TFS shows unchanged files in the list of pending changes
Can TFS Pending Changes show files that are truly changed like SourceGear Vault?

Team Foundation Server - undo file lock for all users or workspaces

I need to create a scheduled task to remove a file lock or undo pending changes for a specific file (let's call this file $\MyProject\MyFile.cs).
I know I can do this via the TFS command line utility using tf undo, which requires you to specify the user and the workspace.
However in this case the scheduled task does not know which user or workspace is locking the file, so I can't specify this in the command.
Is there a way of removing a lock on a file for all users and workspaces?
I had the idea of using tf status command to retrieve the user and workspace the file is locked to, then passing this into my tf undo command, but tf status seems to only show me the user and not the workspace name.
Apolgies in advance if there is already an answer to this question. I've been looking for hours and couldn't find a solution.
Check case: tf.exe undo pending changes from other users, the answer in this case gave the solution to get all workspace:
tf status supports a /format parameter. The brief output (which is the default) doesn't include the workspace. the detailed one does.
tf status "$/MyProject" /s:MyServer /u:* /recursive /format:detailed

How to handle missing 'added' files during check-in

I have a bunch of files in the 'added' state across many folders that were accidentally deleted from the file system. How can I easily either undo them or convert all of them to a 'delete' status? I'd prefer not to have to manually undo each file one at a time.
What I've tried so far:
In the Pending Changes window, using the Undo command for each missing file is tedious. Since the window does not identify which files are missing, I have to compare this window to the file explorer and compare the contents of each folder.
The answers for this similar question don't apply to me because my files are in the 'added' state, so comparing my workspace to the server will not identify these missing files.
I've looked through the TFS Power Tools for something to identify missing files but haven't found anything that directly addresses missing files.
The tfpt online command doesn't address missing files in the 'added' state.
If I read you correctly, in this case your underlying file system and what TFS thinks is on your file system have gotten out of sync.
The best, easiest, way I know how to rectify this is to undo all your changes, then redo the adds, deletes, and edits that you actually require. I know that with many files this will be a pain, but let me reiterate: I mean the best, easiest way and not the fun, effortless way (which I don't think exists)!
Do a 'clean' in your project within Visual Studio, then delete any bin/ and obj/ folders in the source.
Then undo all changes for your project.
If you are using TFS < 2013, I would recommend the use of Team Foundation Power Tools online functionality. For instance:
cd \dev\path\to\project\root\
tfpt online /adds /diff /deletes /recursive .
Otherwise, if you are using TFS 2013, then you can use the built-in 'reconcile' functionality (cannot find a web URL for this, the 2010 docs are incorrect, use 'tf reconcile /?' for a description):
cd \dev\path\to\project\root\
tf reconcile /adds /deletes /diff /recursive /noignore /promote .
With TFS Power Tools installed, run this command from a VS command prompt in the appropriate folder:
tf reconcile /deletes /diff /recursive /noignore /promote
This will display a list of pending changes. The missing files will all be selected with a new status of 'delete'. Click Promote to save the change, then try again to check in.
This is a slight variation of d3r3kk's answer but without the /add flag which causes more files to be selected than necessary.

TF: Checkin only selected files instead of all Pending changes while merging

Using tf.exe, the command line utility for TFS, I've automated the process of merging two branches using tf.exe in a batch file in simple steps:
TF Get... /Recursive
TF Merge... /Recursive
However, while checking in the changes, "TF Checkin" Dialog shows all the pending changes selected in the dialog whether using /Recursive or not.
What I want: To select only modified files in my selected folder instead of all the pending changes. Please note that this is a random thing, as I have 100's of files in my folders, so only files changed during Merge should be selected (definitely these would be modified ones).
Solution I expect: To create a separate Workspace for my automated merge process. This would isolate the checkin process and would select only the changes made through this Workspace.
Another Possibility: Is it possible to Checkin files in a specific folder and ignore rest of the pending changes?
Thankx
I'm not sure I understand your problem right, but it is indeed possible to checkin only files in a specific folder. To avoid checkin problems you should probably do a "resolve" first. For instance
tf.exe get /r c:\src\branch1\project1 c:\src\branch2\project1
tf.exe merge c:\src\branch1\project1 c:\src\branch2\project1 /r /noprompt
tf.exe resolve c:\src\branch2\project1 /r /auto:acceptTheirs /noprompt
tf.exe checkin c:\src\branch2\project1 /r /noprompt /override:"done by script"
You should always do a /noprompt when running tf.exe from a script/automation process. This is to avoid popups. In the resolve I put /auto:acceptTheirs which will take the changes from the source branch when a conflicting change occurs. There are several different options here, you will have to concider which suits your purpose. /override on the checkin will override any checkin policies, which is probably (but not necessarily) a good idea from a script.
The approach with creating new workspaces every time is something I would try to avoid if possible. Creating and deleting a workspace is a heavy process, and in my experience it is difficult to keep track of all the workspaces so I usually end up with lots and lots of unused workspaces that needs to be removed.
Just discovered that we can also use Repository Address instead of hard-coding paths:
tf checkin $/MainRep/Playground/MyFolder/HTMLLogViewer /r
Would give same facility and would prevent us from using hard coded paths.

How to get comment from MSVS2010 when I try and check in from CMD?

I have several projects on the go. So I download a copy of the code to a workspace, work on that and then shelve it for my manager and others to review with comments (this is done from within the MSVS2010 IDE's Pending Changes window/tab). Then when that is completed, I check in the changes.
Thing is, I would like not to have to load up the MSVS2010 environment every time I just have to do a check in. It's bulky and has a lot of windows popping up that I would like to avoid. So I would like to just execute a command line command to do the check in for me.
I tried tf checkin /shelveset:<name-of-shelveset> and I get this error:
TF204000: The Team Foundation server to which your team project is connected does not support the CheckInShelveset command.
Using tf checkin <path-to-workspace> worked but I don't have the shelveset comments.
Is there a way to get the comments populated with the shelveset comments I used last from within MSVS2010 without having to load it up?
I suggest you to add your profil as owner of shelveset, it's optional but important when shelveset can be created by lot of users
tf checkin /shelveset:<name-of-shelveset>;shelvesetowner

Resources