Freigeben über


How To: Unlock/Undo a File that is Locked/Checked out

As the number of TFS users grows inside MS, rarely does a day go by where I don’t get forwarded a question where someone is asking how to do something in Version Control.  In the past, I’d simply respond to the person that asked the question, and go on my way.  Recently I realized that I should start blogging the answers to these questions so that the entire community can benefit from the answers.  My previous post was one of these questions, as is this one.  From now on, I’ll start tagging any posts on how to do something as a “How To” post.  And now, on to the answer about undo/unlock…

 

How to: Unlock/Undo an File that is Locked/Checked out

Any user that wants to undo any pending change created by another user will need the UndoOther permission.  With this permission, any item (for which the permission is granted) can have its pending changes undone.  To undo a pending lock, the UnlockOther permission is needed in addition to the UndoOther permission.  Once these permissions are granted, a user can go to the command line and undo the change using the tf undo command:

tf undo /workspace:WorkspaceName;WorkspaceOwner $/PathToTheItemToUndo

What does it actually mean to undo another person’s change?  It means that the server’s record of the add, edit, rename, delete, etc, will be removed, and users will no longer see the pending changes in SCE.  One important fact to note is that this will not revert any local file contents that were modified as a part of the pending change.

Say for example, I checked out a file and edited the contents of that file, saving my changes locally.  This would pend an edit for that file, and any user with permissions to view that file would see my edit.  Now, if an administrator with UndoOther permission came along and performed an undo of my change on the file, that would make my pending edit disappear from the server, and users (including myself) would no longer see the file marked as having an edit. 

What does it mean for the owner of the pending change to have it undone by another user?  Using the previous example, if I went to the mapped location where the file was saved on disk, that file would still be saved with the edits that I made.  It would continue to be marked as writable, preventing it from being automatically overwritten if I performed a Get Latest.  To return the file to the state on the server, I’ll need to perform a force Get operation (since the server thinks mine is unmodified it won’t download with a normal Get).  If another user updates the file and checks it in, when I perform a Get, I’ll get a writable file conflict where I can overwrite my file, or merge the contents.

 

Details on the Undo Command: https://msdn.microsoft.com/en-us/library/c72skhw4.aspx

Details on TFS Permissions: https://msdn.microsoft.com/en-us/library/ms252587.aspx

Comments