Using TF.exe in Real World scenarios

If You want to do anything advanced with Team Foundation Source Control, then you will need to get friendly with the command line. This used to be called h.exe but is now tf.exe.

The command line reference can be found at,vs.80).aspx. Fire up a Visual Studio Command Prompt and away you go.  Once you get your head around it, the command line tool is really powerful.

To unlock a file, first you need to make a note of the full path to the problem files.  Sadly, I don’t think there is anywhere that you can copy this into the clipboard from in the Visual Studio UI (if anyone finds a place then let me know!!).  Then you need to pull up the detailed information on that file:-

tf status $/MyProject/MyPath/MyFile.cs /server:my_server /format:detailed

You’ll get something like:-


  User       : MY_DOMAIN\my_user

  Date       : Thursday, October 12, 2005 11:25:00 PM

  Lock       : checkout

  Change     : edit

  Workspace  : WorkSpaceName

  Local item : [WorkSpaceName] D:\projects\MyProject\MyPath\MyFile.cs

  File type  : Windows-1252

There is an unlock command – if this works it will be cool as it would mean that the developer wouldn’t loose their changes.  I heard that this didn’t work properly for Beta 2 – should be fixed now, the syntax is below:-

tf lock $/MyProject/MyPath/MyFile.cs /lock:none /workspacename:WorkSpaceName /server:my_server

There is also an Undo command.  It would get rid of any pending changes that the developer had made and they will lose any work they were doing.  The syntax for Undo is:-

tf undo /workspacename:WorkSpaceName;dev_username /server:my_server $/MyProject/MyPath/MyFile.cs

We had a developer leave our company with some files still checked out when we were running on Beta 2.  To find out which workspaces the developer had we used:-

tf workspaces /owner:dev_username /computer:* /server:my_server

Then we deleted them.  Deleting the workspace also removes the lock on the files.  The command to delete a workspace is:-

tf workspace /delete /server:your_tf_server workspacename;workspaceowner

I read somewhere that an graphical admin tool will be available as a download post release for Team Foundation Server. If not, I think I’ve found myself a new project..

After the umpteenth time of typing “tf –?” only to have it launch the MSDN documentation that usually isn’t installed in my Dogfood environment, I threw together a text file that contains the sort of memory jogging help that I (and probably others) would like to see printed in the console (hint hint).  I thought it would be nice to share it.


Add        tf add itemspec [lock:none|checkin|checkout] [/type:filetype]
              [/noprompt] [/recursive]
Branch     tf branch olditem newitem [/version:versionspec] [/noget] [/lock]
              [/noprompt] [/recursive]
Branches   tf branches [/s:servername] itemspec
Changeset  tf changeset [/comment:comment|@commentfile] /s:servername
              [/notes:("NoteFieldName"="NoteFieldValue"|@notefile)] [/noprompt]
Checkin    tf checkin [/author:authorname] [/comment:("comment"|@commentfile)]
              [/notes:("Note Name"="note text"|@notefile)]
              [/override:reason|@reason] [/recursive] filespec ...]
Checkout   tf checkout|edit [/lock:(none|checkin|checkout)] [/recursive]
              [/type:encoding] itemspec
Configure  tf configure pathtoproject /server:servername
Delete     tf delete [/lock:(none|checkin|checkout)] [/recursive] itemspec
Difference tf difference itemspec [/version:versionspec] [/type:filetype]
              [/format:(visual|unix|ss)] [/ignorespace]
              [/ignoreeol] [/ignorecase] [/recursive] [/options:"options"]
           tf difference itemspec itemspec2 [/type:filetype]
              [/format:(visual|unix|ss)] [/ignorespace] [/ignoreeol]
              [/ignorecase] [/recursive] [/options:"options"]
           tf difference [/shelveset:[shelvesetowner;]shelvesetname]
              shelveset_itemspec [/server:serverURL]
              [/type:filetype] [/format:(visual|unix|ss)] [/ignorespace]
              [/ignoreeol] [/ignorecase] [/recursive] [/options:"options"]
           tf difference /configure
Dir        tf dir [/s:servername] itemspec [/version:versionspec] [/recursive]
              [/folders] [/deleted]
Get        tf get itemspec [/version:versionspec] [/all] [/overwrite] [/force]
              [/preview] [/recursive] [/noprompt]
Help       tf help commandname
History    tf history [/s:servername] itemspec [/version:versionspec]
              [/stopafter:number] [/recursive]
              [/user:username] [/format:(brief|detailed)] [/slotmode]
Label      tf label [/s:servername]  labelname@scope [/owner:ownername]
              itemspec [/version:versionspec]
              [/comment:("comment"|@commentfile)] [/child:(replace|merge)]
           tf label [/s:servername] [/delete] labelname@scope
              [/owner:ownername] itemspec [/version:versionspec]
Labels     tf labels [/owner:ownername] [/format:(brief|detailed)]
              [/s:servername] [labelname]
Lock       tf lock itemspec /lock:(none|checkout|checkin)
              [/workspace:workspacename] [/server:serverURL] [/recursive]
Merge      tf merge  [/recursive] [/force] [/candidate] [/discard]
              [/lock:none|checkin|checkout] [/preview] [/baseless] [/nosummary]
              source destination
Merges     tf merges [/s:servername]

destination [/recursive] Permission tf permission [/allow:(* |perm1[,perm2,…]] [/deny:(*|perm1[,perm2,...])] [/remove:(* |perm1[,perm2,...])] [/inherit:yes|no] [/user:username1[,username2,…]] [/recursive] [/group:groupname1[,groupname2,...]] [/server:servername] itemspec Properties tf properties [/recursive] itemspec Rename tf rename [/lock:(none|checkout|checkin)] olditem newitem Resolve tf resolve itemspec [auto:(AcceptMerge|AcceptTheirs|AcceptYours)] [/preview] [(/overridetype:overridetype | /converttotype:converttype)] [/recursive] Shelve tf shelve [/move] [/replace] [/comment:(@commentfile|"comment")] [/recursive] shelvesetname[;owner] filespec tf shelve /delete [/server:serverURL] shelvesetname[;owner] Shelvesets tf shelvesets [/owner:ownername] [/format:(brief|detailed)] [/server:serverURL] shelvesetname Status tf status itemspec [/s:servername] ([/workspace:workspacename[;workspaceowner]] | [/shelveset:shelvesetname[;shelvesetowner]]) [/format:(brief|detailed)] [/recursive] [/user:(*|username)] Undelete tf undelete [/noget] [/lock:(none|checkin|checkout)] [/newname:name] [/recursive] itemspec[;deletionID] Undo tf undo [/workspace:workspacename [;workspaceowner]] [/s:servername] [/recursive] itemspec Unlabel tf unlabel [/s:servername] [/recursive] labelname itemspec Unshelve tf unshelve [/move] [shelvesetname[;username]] itemspec View tf view [/s:servername] [/console] [/noprompt] itemspec [/version:versionspec] WorkFold tf workfold localfolder tf workfold [/workspace: workspacename] tf workfold [/s:servername] [/workspace: workspacename] repositoryfolder tf workfold [/map] [/s:servername] [/workspace: workspacename] repositoryfolder|localfolder tf workfold /unmap [/s:servername] [/workspace: workspacename] [/recursive] (repositoryfolder|localfolder) tf workfold /cloak (repositoryfolder|localfolder) [/workspace: workspacename] [/s:servername] tf workfold /decloak (repositoryfolder|localfolder) [/workspace:workspacename] [/s:servername] Workspace tf workspace /new [/noprompt] [/template:workspacename[;workspaceowner]] [/computer:computername] [/comment:("comment"|@commentfile)] [/s:servername] tf workspace /delete [/s:servername] workspacename[;workspaceowner] tf workspace [/s:servername] [/comment:comment] [/newname:workspacename] workspacename[;workspaceowner] Workspaces tf workspaces [/owner:ownername] [/computer:computername] [/s:servername] [/format:(brief|detailed)] [/updateUserName:oldusername] [/updateComputerName:oldcomputername] workspacename ITEMSPECS Can contain wildcards *, ? and # Can contain relative path parts . and .. Can reference file system or UNC paths mapped to a workspace or server paths (which start with $/). You can usually specify more than one file separated by spaces for an itemspec (useful for edit, add, delete commands) VERSIONSPECS Date/Time Dmm/dd/yyyy Changeset number Cnnnnnn Label Llabelname Latest version T Workspace Wworkspacename;workspaceowner ALIASES /changeset /G /noprompt /I /comment /C /owner /O /computer /M /recursive /R /delete /D /server /S /force /P /slotmode /X /format /F /template /T /help /?,/H /user /U /lock /K /version /V /login /Y /workplace /W /newname /N

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s