TFS: How can you Undo Checkout of Unmodified files in a batch file
Solution 1
Take a look on Undo Unchanged command of the Team Foundation Server Power Tools August 2011
c:\myProject> tfpt uu . /noget /recursive
Thanks Matt Florence for link update.
Thanks Ray Vega for actual syntax.
Solution 2
Install Team Foundation Server Power Tools and run the following from the command line using tfpt.exe at the root of your project's workspace directory:
c:\myProject> tfpt uu . /noget /recursive
Including /noget
is highly recommended since it prevents a forced 'get latest' of all your project's files which depending on the total number can take a extremely long time.
Solution 3
Thank you @mike & @ray,
I wish to make it easier.
In VS, at Tools menu, click on "External Tools".
Click Add.
Enter title.
Command: tfpt.exe
Arguments: uu . /noget /recursive
Initial Directory: [you can choose from the arrow button].
Two new command are added to Tools menu.
Use them when needed.
Enjoy,
Ofir
Solution 4
- Right-click on your project
- Select undo checkout, then just click okay, or whatever confirmation is left...
- Then, while undoing checkout, for every file that has REAL changes in it, a prompt will ask you to confirm the check out for that file... simply click "No to All"
Visual studio will know if the checked out file has changes or none.
WARNING: This method also removes new files, i.e. files that are not yet checked in to TFS. If you want to keep these files then simply exclude them from the set of files you "undo".
Solution 5
Updated this question with an answer when working with TFS2017 and VS2017/VS2019 only.
The power tools does not exist for TFS 2017 and the old ones can't work well together with it, but apparently most of the functionality has been moved to VS2017 itself or plugins (see below).
Visual Studio 2017/2019 Extension
Some actions like undo unchanged files have moved to an
"Undo Unchanged" button location:
Known bug
You have to open the 'Source Control Explorer' (and leave it open) so that the 'Undo Unchanged' is displayed in the Action menu of the Pending Changes view. reported here.
Windows Shell Integration Extension
Also, you can still set up Windows shell integration through an separate installer which is no longer linked to TFS Power Tools.
The windows shell integration do not work exactly the same as the powertools before, but the most important actions worked for me.
Related videos on Youtube
Erik Decker
Updated on July 01, 2020Comments
-
Erik Decker almost 4 years
We use a batch file to generate code, and it automatically checks out the generated files from Team Foundation Server (TFS) so that it can regenerate them. The majority of these files are not modified, but the generator does not know this ahead of time.
The "tfs undo" command undoes the checkout, but prompts if some have been modified (which we don't want to do). We also do not want to check in the generated files right away.
Is there a command (or series of commands) to undo checkout of all unmodified files without prompting the user?
-
Elaskanator over 5 yearsNote that manually undoing all changes with the expectation of choosing "No to all" when prompted about files that have changed will not work correctly, as it will undo
ADD
changes without prompting (see Ray's answer).
-
-
Erik Decker over 15 yearsThanks for that, however we do not want to check in the modified files at that time. The modified ones should not be checked in till the feature is done, but the unmodified ones should be removed so the dev can review the changes.
-
rikoe almost 13 yearsThis should be the accepted answer, it has all the relevant details (as proved by the higher score).
-
mcw over 12 yearsThis should be edited / merged to contain the usage information as part of the answer content.
-
rohancragg over 12 yearsCool. Also, why not add this as a permanent 'External Tool' to Visual Studio. Taking this as an example: blog.kurtschindler.net/post/… Command: [your installation dir]\TFPT.EXE Arguments: uu . /noget /recursive Initial directory: $(SolutionDir)
-
Byron Whitlock over 12 yearsYou really want to read this post: aaubry.net/undo-checkout-on-unchanged-files-tfs.html
-
Johnny Kauffman over 12 yearsThe question specifies doing this operation without the prompt, but none of the answers seem to address this. If you need this, the additional /noprompt is the option you're looking for. The PowerTools documentation is missing this! It lists this option for a few of the commands, but not this one (UU). Beware!
-
vidstige about 12 yearshmm, somehing that almost everyone does several times daily: "Lets put it in a separate installer called Power Tools"... sigh
-
Mike Chaliy about 12 years@vidstige , this his how it was years ago(answer is Feb 2009). May be now better solution exists.
-
vidstige about 12 years@Mike Chaliy you would think. I'm trying out TFS right now, and was searching on how to do this and ended up here.
-
Richard about 12 yearsEither use robocopy or a VCS, using a mixture is always going to give inconsistencies. Much better would be to populate each machine from VCS directly.
-
Jeremy Wiebe over 11 yearsFYI: VS 2012 Power Tools is here: visualstudiogallery.msdn.microsoft.com/… Meaning it's still not baked into the core toolset. sadtrombone
-
Mario over 11 yearsVery cool. You can go one step further too and add a shortcut. Note how far down your added command is (e.g. it may be the fourth). Then to to Tools -> Options -> Environment -> Keyboard -> and type in the 'Show commands containing' textbox "Tools.External" and assign a shortcut. For instance I selected Tools.ExternalCommand4 since my newly added undo command was the fourth one down. I then assigned shortcut keys Ctrl + Alt + U, Ctrl + Alt + U
-
user1164178 over 9 yearsIt doesn't work if your changes are merges. It seems tfpt uu always considers a merge to be a real change, even if there is no file change, and there's no option to flip that behaviour. It's ok as a default behaviour, but sometimes it's not what you want.
-
Ray over 9 years@user20358 either
cd
to where your workspace directory is (for example, mine wasc:\myProject
) or explicitly include it afteruu
(replacing the period.
with it) -
James over 9 yearsWas going to down vote, but "At work, we all hate TFS." saved it.
-
shortstuffsushi about 8 years
Be aware that this method also removes added files that are not yet checked in from TFS.
... yeah, that's a pretty immediate disqualifier. -
matthewdaniel almost 8 yearsany idea how to force this command so i can throw it in a powershell script and run it as a scheduled task every few minutes?
-
Shay almost 8 yearsCould we please have an updated version of this? If found tf.exe but what is uu command? it tells me Unrecognized command: uu. Thanks for help
-
Sean Kelly almost 8 years@Shay : Works for me in VS2015 with the latest TFS power tools installed.
-
KoViMa over 7 yearsIt works for mine Baseless branches merge. Thanks. Usually in this case VS marked All files in solution as changed.
-
Squirrelkiller about 7 years2017 checking in, would laos like to know about a /force switch. I have to confirm it every time :(
-
Squirrelkiller about 7 yearsDoes this have a force switch, like /Y or /force? I'm always asked if really want to undo it, and I'd like to have that automated. Put /Y there, but it tells me The Option Y requires a value.
-
andersand about 7 years@matthewdaniel The switch
/noprompt
is what you are looking for (as mentioned by @johnny-kauffman in another answer's comment) -
Ryan Mann over 6 yearsWhy do people check out everything? You can just checkout the files you need to change, you can do get's on things without checking them out.
-
Ievgen about 6 yearsthis is a hell when nuget do checkout for a 10000 files that are not required to be updated.
-
Schwarzie2478 over 5 yearsI noticed in the question, that they want to script it, for that I don't have a solution, I'm afraid
-
Elaskanator over 5 years@RyanMann one use case is migrating changes between branches, because the TFS Power Tools
/migrate
command is bugged for file rename changes (it deletes the file with the old name and creates one with the new name, which cuts the TFS history on the file). -
Elaskanator over 5 yearsThis command no longer works in 2015, as it says I have no redundant changes no matter what (assuming the workspace mappings are even configured).
-
Elaskanator over 5 years@user20358 Also note that using TFPT in VS2012 actually runs from VS2010, so you need to configure your TFS connection in VS2010 for it to work.
-
Elaskanator over 5 years@RobertWagner If you have a gated build, then you can cancel (if it doesn't abort upon identical file detection) when you get the popup alert that the changes have to be built first.
-
Jonathan F. over 5 yearsI can't find the "Undo Unchanged" option in VS2017 after installing the linked extension. Did I miss something ?
-
Schwarzie2478 over 5 yearsI haven't used it very much. When I used it to test it for my customer, I had to click around a bit in Team Explorer and make sure that there were changes to undo. It's possible that it only appears when you only have pending changes queued for a commit that this option appears. ( or one branch changes only)...
-
MatrixRonny about 5 years@Erzékiel The option appears only when Solution Explorer is open and ready.
-
Jonathan F. about 5 yearsWell I tried what you guys said but nothing appeared.
-
Christian almost 5 yearsThis extension works sometimes and its presence is linked to having the TFS Source Control Explorer open and not Solution Explorer (as some wrongly pointed out) - do not mix up the two different control windows. However; when I say sometimes, its because it comes and goes. Right now I dont have it, I did a month ago. Its a tiny bit buggy and I fear other extensions is the culprit, such as Resharper and the like.
-
Christian almost 5 yearsplease be advised as this cannot be emphasised enough. Newly added files to the project are also removed with this approach. This is mentioned on serveral of the other answers as well.
-
Christian almost 4 yearsWe Want TFS Power Tools Back For VS2019!
-
Kiruahxh over 2 yearsThis extension works, however it still touches files modified date which makes VisualStudio recompile everything -_-