简体   繁体   中英

Team foundation client command to reset workspace

Is there a command (or series of commands) to sync a TFVC workspace with the server, ensuring that what's on disk exactly matches what's checked in to the server.

tf vc scorch almost does what's needed, in that it syncs the client workspace with the server's version of that workspace, but if a new item's been created on the client and added to source control, though not yet checked in, that item remains after scorch is run. NB: I'm using the TF Client version of scorch rather than the power tools version, as I'm working with VS2017 ( scorch is supported from VS2013 SP1), should that make any difference.

Related, I'm aware that power tools includes a treeclean command; however that only impacts items not under source control; not those added to version control but not checked in. https://adamprescott.net/2011/09/12/clean-tfs-workspaces-with-scorch-treeclean/ .

The only way I can think of to achieve this is to delete ( tf vc workspace /delete /collection:"https://$MyInstance.visualstudio.com/DefaultCollection" $MyWorkspace ) & recreate ( tf workspace /new $MyWorkspace /collection:"https://$MyInstance.visualstudio.com/DefaultCollection" ) the workspace, before running a recursive get to repopulate the new folder. However, that feels like the long-way-round for something which I'd assume would be simple...

We're using TFVC rather than Git because we're working with Dynamics AX , which does not natively support Git .

The reason I want to delete such objects is because this script will run on a build server, where I want to ensure we build exactly what's checked in to source control. Whilst in theory no one should be creating new objects on the build server, I don't like to rely on that assumption / want to make this script as robust as possible.

I'd missed the undo command: TF.exe vc undo * /recursive /noprompt .

Running this command before running get and then scorch ensures that my workspace exactly matches the latest server version.

Here's the complete code used to sync the current workspace with the server. NB: This command assumes that tf.exe 's directory is included in the path environment variable (or you can replace tf with "...\\path\\to\\tf.exe" ), that the current/working directory is mapped in source control, and that your tf credentials are cached (otherwise include the /login argument with username and password). I've not included /all , '/overwrite', or '/force' on the get command, since scorch will cover this anyway; the main purpose of the get here is to ensure our workspace is "pointing at" the latest definition.

tf vc undo * /recursive /noprompt
tf vc get * /recursive /noprompt
tf vc scorch * /recursive /noprompt /diff 

NB: The vc above is superfluous / just ensures that were there a possibility for ambiguity the system would know to use tfvc 's version of the command instead of the git version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM