Keep in mind that you will need the appropriate rights. The permissions are called “Undo other users’ changes” and “Unlock other users’ changes”. These permissions can be viewed by
- Right-clicking the desired project, folder, or file in Source Control Explorer.
- Select Properties.
- Select the Security tab.
- Select the appropriate user or group in the Users and Groups section at the top.
- View the “Permissions for [user/group]:” section at the bottom.

Next way is:
If you login into the source control with the admin account, you will be able to force undo checkout, or check in with any file you provide.
Undo TFS code checked by another user:
You must have admin right and then by using below command you can undo code which is checked by other user who is not in company now. Use * if you want to undo all file with in given folder or in case of single file pass the name of specific file.
Syntax is:
tf undo {file path} /workspace:{workspace};{username}
Sample command are below
tf undo $/CmpProject/Project_2/MAIN/APP1.1/Encrypt.sln /workspace:WorkspaceName
tf undo $/CmpProject/Project_2/MAIN/APP1.1/* /workspace:WorkspaceName
If you have administrative rights to the collection, you can use the TF command located in the Visual Studio\Common7\IDE directory to do this without having to install another tool.
List all the workspaces associated with the user:
TF workspaces /collection:"http://tfsserver:8080/tfs/collection_name" /owner:owner_id
This will return the list of workspaces owned by the user and computer they are associated with
To delete a given workspace:
TF workspace /delete workspacename;owner_id /collection:"http://tfsserver:8080/tfs/collection_name"
Nutshell
If you are admin then login into the source control with your admin account, you will be able to force undo checkout, or check in with any file you provide.
Check More:
- Get TFS to ignore NuGet packages folder
- Unlocking files and folders locked by some employee on TFS
- How can I clear the NuGet package cache using the command line?
- How to get the nuget cache folder location programmatically
I hope you enjoyed reading this post. For more information you can check out Microsoft learn.
For more information you can visit our C# Section for more such posts.