How to add to visual studio solution a file that exists in TFS? - visual-studio

I've deleted a file by accident. Then I created another file with the same name. When I tried to check in the change, it didn't work out and got an error. I undid the changes then deleted the file, there's no more error when I try to check in.
I'd like now to get the latest version of the file before I deleted it.
Thanks for helping.

In TFS, a deletion only takes effect when you check in the said deletion change, and thankfully, this operation is reversible.
Here are the most common recovery scenarios, assuming that the file already had revisions stored in TFS before the accidental deletion:
If the file is still visible in the Source Control Explorer and is marked for deletion (under the Pending Change column):
Then it means that you've deleted the file from your solution (and file system), but that you didn't checked in the changes yet.
Use the "Undo" command of its contextual menu to restore the file in your workspace to its latest version before deletion.
From there, you'll be able to add the restored file to your solution.
If the file is still visible in the Source Control Explorer and is not marked for deletion:
Then it means that you've deleted the file from your file system.
Use the "Get Specific Version" command of the file's contextual menu to restore it in your workspace. In the "Get" window, select "Latest Version" and enable both options.
From there, you'll be able to add the restored file to your solution.
If the file is not visible in the Source Control Explorer:
Then it means that you've checked in the deletion change.
Turn on the "View deleted files" option of the Source Control Explorer (usually the 2nd button of its toolbar) to see your deleted file.
Use the "Undelete" command of the file's contextual menu to restore it in your workspace.
From there, you'll be able to add the restored file to your solution and you'll eventually have to check in the undeleted file to make it available to others, since this file only exists in your workspace.

Related

Restore deleted files in visual studio code in the code management menu

I am really devastated because I have accidentally deleted 3 of my files in Visual Studio Code. I did it through the Source Code Management menu on the left side. Now my question... Is there any possibility to restore the 3 files I deleted like this? I would appreciate any answer and maybe you want to know: I use Windows
:-(
I tried to look into the recycle bin of windows but it isn't there. :-(
vscode maintains a file-history using its latest TIMELINE view.
How to restore deleted git-untracked files in vscode:
Create the files with the same name at the same directory.
Go to TIMELINE on the File Explorer.
You can get the older versions of the files.
No, you cannot recover those files using VS Code or standard tools. They aren't put in the recycling bin (or your operating system's equivalent), they are removed using git cleanor git reset --hard. Condolences :-(
There are of course utilities for recovering deleted files that may or may not be successful, but that is outside the scope of this question.
I accidentally removed a file that wasn't even checked in to git. Google brought me here. The file wasn't in the Trash can either (Ubuntu 18.4 VS Code 1.31.1). Looking at the git output I can see that it used git clean -f to remove it by force).
Fortunately the file was still in the editor. Just press Ctrl+P and type the file name. It should show up in the list of files and if you open it, it says "FILE_NAME (deleted from disk)" on the tab. Just copy/paste the content to where it should be.
if you accidently click the delete menu option right below rename, as long as you don't panic and like restart your computer or something you can open that directory in the file explorer on your computer
and right click.
there should be options there to undo delete or whatever else you did to the directory.
Open VSCode's command menu, and type "Local History" and select "Local History: Find Entry to Restore." Then type the name of the file you deleted.
This has worked for me when "undo" in the file tree has not.
Super easy, and has saved me from despair.

How do I get Visual Studio Team Foundation Server to see I moved code to a different folder?

I moved some code from my c drive to my d drive. When I opened the solution, it told me that:
The solution appears to be under source control, but its binding
information cannot be found. Because it is not possible to recover
this missing information automatically, the projects whose bindings
are missing will be treated as not under source control.
So I tried permanently removing the bindings and downloaded the latest version. Now my changes don't register as pending changes.
I've tried selecting the solution in the Solution Explorer and File => Source Control => Change Source control, but it does not let me bind. Server Name and Server Binding columns have "".
Generally speaking, the location of code on your machine is dependent upon where your workspace is located.
If you move your workspace to the D: drive, then there shouldn't be an issue.
However, if you simply used Explorer to copy the files to the new location, then VS isn't going to be able to maintain the bindings.
From the Workspace Editor you can map the entire tree, solutions or even individual projects to a new location.
First off, put it back and undo the changes.
Then, Go to File | Source Control | Workspaces.
Click on the work space name and then the "Edit..." button.
In the working folders area select the source control folder you want to move and give it a new local folder location.
You will need to edit your Workspaces for TFS Server to know the change that has happened at your local machine. To edit your workspace, in Visual Studio:
ensure you have no pending changes; also copy your source code folder to some location temporarily, just to be safe (you can remove after you are all set)
go to Source Control Explorer
locate the "Workspace:" dropdown
select the item "Workspaces" from the dropdown list (you will get a dialog titled "Manage Workspaces"
if you have multiple Workspaces, select the appropriate one from the list in the dialog
click on "Edit" button (you will get an "Edit Workspace..." dialog)
down below in the dialog, you will see "Working folders" grid
click on appropriate row from the grid and modify the "Local folder" path to set to your new folder location
Sometimes TFS and Visual Studio have issues in getting these workspace changes synchronized. I would always close Visual Studio and re-launch it to get my changes synchronized anytime after I make Workspace related changes.
Hope this helps.
the most crude way here (I don't know if there is any other way)
is to put the folder back to its old location , Check in your changes
then remap the project to the new folder
When you move files/folders to make the moves pending changes you need to use a TFS client to do the moves.
For one or two files the Team Explorer UI is OK, for more the command line is easiest.
See tf.exe rename on MSDN (tf move is an alias for rename). There is also step by step help on using the GUI: Move, Rename, and Delete Version-Controlled Files and Folders.

Cannot eliminate phantom pending TFS change

Somehow, due to folder renamings and various other source code changes, I'm having an irritating problem. I'm showing a pending change for a file that cannot be undone in TFS.
This is a little hard to completely explain. Here is what the directory/file structure looks like in TFS:
RootFolder
Folder
FileA
FileB
OldFolderThatWasRenamedToFolder (shows add icon)
FileA (shows "edit" pending change)
"OldFolderThatWasRenamedToFolder" had been renamed to "Folder" and is committed to TFS like that. The "FileA" under that non-existing folder references the same file as "Folder/FileA" but registers as a different file; for example, if I change "Folder/FileA," pending changes are shown for both "files." Whenever I undo pending changes for the phantom file, TFS reports the error:
No pending changes were found for .../Folder/FileA.
I cannot get rid of this annoying false pending change. I've done an update in the folder forcing an overwrite and even deleted the folder prior to the update. How can I eliminate this phantom pending change?
Update:
I found a potential clue. When I compare the "pending" file with the latest, no changes are detected, but when comparing with the "Workspace version," the file is compared with an older version of the file. I've recently tried deleting my workspace and creating a new one, but the same problem persists. What exactly is going on? Where are these pending changes even stored? Is there some file I can manually edit?
In visual studio 2010, you can right-click on the phantom pending check-in on the "Pending Changes" panel and click "Undo..." on the popup menu, then click button "Undo Changes" on the dialog box "Undo Pending Changes", the phantom pending check-in will be removed from the list.
You should be able to undo the pending change with a 3rd party tool called TFS Sidekicks.
It is a free set of utilities by Attrice. I use it especially when I (or a client) come across such problems, as well as permissions issues, and the like.
Moreover, the tool will allow an administrator to do the same for other users. That means that it will solve situations where code is marked as checked out by a user that may no longer exist in the system.
Download it at http://www.attrice.info/cm/tfs/index.htm
Hope this helps.
I figured out a way to fix this using the tf.exe command line. By entering this:
tf undo /workspace:MyWorkspace $/.../RootFolder/OldFolderThatWasRenamedToFolder/FileA
...I was able to undo the pending change. If anyone knows how to do this same thing without resorting to the command line, I'll accept their answer instead.
I know this is an old post, but I expierenced the same thing.
What I found: John Kurlak's command line worked for me. I wanted to try something so I ran the TF MERGE again. This time I closed all Visual Studios open and then reopened it. The files showed up in Pending Changes and was able to Undo from there.
I know this is an old question, but I just faced that issue and I was not able to figure this out with sidekicks or tf command line tool. In my case the solution was close the solution and delete the .suo file.
John Kurlak's comment helped me a lot, but let me describe what issue happened in my case and how I solved it.
I've tried what he has suggested:
I opened the developer console, did a cd to the directory of my branch, and ran:
tf undo * /recursive
Then selected "All" when the tool asked "Undo your changes...? (Yes/No/All)".
In my case that was not enough, because NUGET left some files which were not added to TFS. That caused the tf tool to abort with the error:
TF400024: The change on
C:(SomePath)\themes\base\images\ui-icons_cd0a0a_256x240.png cannot be
undone because a file already exists at
C:(SomePath)\themes\base\images\ui-icons_cd0a0a_256x240.png. The file
must be deleted from disk for the undo to succeed.
In this case, I had to delete those files mentioned manually, and then retry until it succeeded. That had to be done a few times.
Note:
Those files can be found easier in the file explorer if you have the TFS power tools installed, because the files belonging to TFS have a green triangle in their icons, the other filies (the ones you need to delete) not.
I had a similar issue with a project that is stuck in AX version control/pending objects with “Add” action. I could not get rid of it by clicking on “Undo checkout” because it no longer exists in AX projects, local repository, nor in VSTS. To get rid of it, I created the project in AX/projects/shared then was able to get rid of it by going to AX version control/pending objects and clicked on “Undo checkout”. I believe this occurs when you create an object in AX, add it to version control, then rename the object afterwards. Hope this helps.
I am still new to VS2010, but this is how I fixed this issue for me:
Go to Source Control in the Team Explorer panel. In the Source Control Explorer, right-click the directory, project, or source code file for which there are pending changes to be ignored. Select Undo Pending Changes. A modal dialog appears confirming the Pending Changes that will be undone. Select Undo Changes, and voila! No more phantom pending changes.

Borland Starteam incorrect files status

I have some project saved in starteam. As there are a lot of obsolete files I can't check in or check out all project, only changed files. Now I copy project from one computer to another for other developer. I expect starteam treats copied project as new item for check in and check out, but it don't.
Forexample:
I modified file on first computer.
I update list of files on second computer and see this file in "check in" list, as I modified it on second computer.
It is incorrect.
I think there is some configuration file or something like, that saves computer (or user) settings. So when project is copied, settings is copied too.
Do anybody know how to change this configuration to set copied project as new instance of starteam???
You should be able to Right-Click on either the file or a close group of files (such as the Modified group) on the file tab within a project and choose the Update Status option. This will cause StarTeam to analyze the file to try to determine if they truly are the same as what is in source control. Then you can refresh the list and it should change most of your files to current.
There is also a configuration setting under Tools->Personal Options->File tab that is "Use file checksums (MD5) to calculate status". This may be useful to you as a different way to have StarTeam determine if the file on your local disk is the same as what is in source control.
It sounds like you are using a custom filter/query for your check-in list. The status for the files that are copied/moved would be "unknown" and they can still be checked-in by checking the "force check-in" checkbox in the check-in dialog. Just verify that the local version is correct by using compare contents before committing it.
You can try switching from a central file status repository to a "per folder" repository. This will create .sbas folders wherever you check-out files and should maintain status for local files when their containing folder is copied or moved. Look under Tools, Personal Options on the File tab under Repository.

Deleting a folder in TFS

I created a folder in a TFS Project under workspace "CPortalWS". I deleted the workspace, but now I would like to delete the folder in the project and the delete option is not available.
I've tried to create a new workspace mapped to the project but I still don't get the option to delete.
Is this a bug in TFS? How can I delete the folder?
Any help would be appreciated.
Deleting a folder in TFS is a little strange.
You have to:
Create a Workspace
Get the latest source for the folder (to your local machine)
Inside Source Explorer, delete the folder
Check in your changes (this is the step that deletes the folder in Source Control)
only note that delete is not an actual delete.
the folders/files are still there and kept in Version Control, for example for Undelete scenarios.
You can see them and avail the undelete function if you go to "Tools > Options > Source Control > Visual Studio Team Foundation Server" and check "Show deleted items in the Source Control Explorer" and then right-click on one of the deleted folders.
so, if you want real delete, where the folder/files actually go away you need to use the Destroy Command which is only available from the command line, see link below
http://msdn.microsoft.com/en-us/library/bb386005.aspx
When you delete in TFS, it does not remove it from TFS. It maintains a copy of the deleted files, even when you check in the deletion. This can cause some issues.
To permanently delete from TFS, you need to issue a tfs destroy command.
To do this:
Open a Visual Studio Command Prompt.
Issue the following command: tf destroy $/SourceLocation/Folder. Where $/SourceLocation/Folder is the Source location of the deleted folder in TFS.
Please note: This command will also delete the file(s) from disk.
I had a similar issue, where I had 1 folder which despite being deleted from Hard drive, was still showing as in Source Control (with a green + by the folder). It also showed me the content but if I tried to open any, an error message informed me the file wasn't there.
Clicking on any folder didn't show the delete button. I then realised that selecting a file did! If you don't have a file, create a text file and add it to the folder you want to delete (via Source Control). Click this file, note the delete shows. Select a folder and note that the delete disappears but only after half a second. This small delay is actually usable.
I clicked the file, so the delete button is enabled and hovered the mouse above the delete button. Using the keyboard, I did a CTRL + A and as soon as all files and folders were selected I clicked left mouse button. And it worked! Everything was removed, including (and this is the odd thing) the parent folder.
Create a Workspace; and get latest on the base folder; Dont forget to cloak the relevant folders. If you are going to delete the subfolders then cloak all and get latest on the base folder. So you save a lot of time in pulling files.

Resources