TFS: Restore deleted folders and items - tfs

I deleted some files and some folders in TFS. Many check in's later I found out that I need the deleted functionality back in my project.
How can I restore the deleted files and folders?

In Team Explorer (in Visual Studio): Tools | Options | Source Control | Visual Studio Team Foundation Server and select Show Deleted Items...
Then in source control explorer you'll see the items greyed out. You can right click on them and Undelete. (This option will only be available if they, after the undelete, will be included in your current workspace).
NB. in newer versions of Visual Studio (eg. 2013) there is now a button to switch on display of deleted items in the Source Control Explorer's toolbar. Its the second button (here with the VS dark theme):
Alternatively using the TFS PowerToys you can look at history and right click to select "Rollback Entire Changeset": this will create pending changes to revert the changes of the selected changeset.
Edit: Added paragraph on newer versions of VS.

Assuming you successfully undelete as per #Richard's answer, there might still be an issue with the item appearing in Solution Explorer (at least it was for me using Visual Studio 2015). That is to say, the file is restored on your hard drive, in the proper place in your project's folder structure--but it's not showing in VS.
To resolve this, click the Show All Files button in Solution Explorer:
You will see your file, in a ghostly white icon. Right-click on it and select "Include in project". Save and check-in changes. You are back in business.

Recently I faced this issue, accidentally I deleted some classes which weren't checked in, I searched the name of the classes in my project directory (I was working on D365 project there is a bin folder in C:\AOSService\PackagesLocalDirectory\bin\XppSource) and saw that in the bin folder they were existed so I created new classes with the same name and copy the logic.
Also I should mention that no file was in recycle bin.

Related

Why do all my files have a red check next to them when I "check out latest" for the first time from TFS?

I'm going into TFS and creating a mapping to a local folder, then I right click on the folder I want to check out and click on "Get Latest Version". After I have pulled down all the files I open up the solution in VS and in the Solution Explorer window I see all the files (including the solution and project files) have red check boxes next to them. So now it looks like they all need to be checked in because I have made edits! This is not true, I'm checking these fiels out for the first time and haven't made any changes yet.
How do I check out the folder without it looking like there are already edits that need to be checked in? (no red check next to each file)
I had a similar problem (red checks next to everything in the Solution Explorer window). I resolved it by selecting the solution in the Solution Explorer, and then selecting from the menu bar: File > Source Control > Refresh Status. This removed all my red checks.
In Team Explorer (in Visual Studio): Tools | Options | Source Control | Visual Studio Team Foundation Server and select Show Deleted Items...
Then in source control explorer you'll see the items greyed out. You can right click on them and Undelete. (This option will only be available if they, after the undelete, will be included in your current workspace).
The red check marks indicate that there has been a change to the file. Many of these answers for previous versions of Visual Studio seem correct. I use Visual Studio 2017 and using GitHub.
If you have several files with the red check mark:
Right click project
Go to Source Control,
Select Commit,
{Follow standard commit procedure}
Enter your commit message,
Sync,
Push.
If there is just one file or you want to commit the files individually:
Right click each file
Select Commit,
{Follow standard commit procedure}
Enter your commit message,
Sync,
Push.
Right click project
Right click file
Identify Version Control Item Status in Solution Explorer
Checked out
Represents an item for which the current user has a pending change in their current workspace, and the item is not exclusively locked.
For me, the red X's were appearing because I had moved the files from a Feature branch to an Archived branch (After a successful merge into the main branch).
I tried File > Source Control > Refresh Status however this didn't help.
I didn't want to go messing with cache files.
I found this answer:
Go to Tools/Options/Source Control/Visaul Studio Team Foundation Server. Check if there is a check mark next to "Show deleted items in the Source Control Explorer".
I had to right click the particular folder and selected the "Source control" ->"undo pending changes" option.
Just spent 4 hours trying to rectify this and none of the solutions above worked for me, not even unmapping and re-mapping the solution.
In case anyone still has this problem, try removing your workspace and re-adding it.
Below are the instructions for removing and re-adding a workspace in Visual Studio 2019, but it should be similar for any other version as well:
Go to Team Explorer, scroll down and under Solutions you will see
Workspace: "Name of your workspace"
Click on the arrow next to it and select Manage Workspaces
A dialog box containing your workspace will open. Click Edit to see
the paths for Source Control Folder and Local Folder. Make a note of
them as it will be useful for re-adding the workspace. Close the Edit
Workspace window, select the Workspace and press Remove
Once it is removed, select Add then enter the paths that you noted
earlier. Press OK to confirm and it should re-add your workspace
without the check marks.
In Visual studio 2019, I have unloaded the project and I have reloaded the project. Then it went.
Working solution tested. It turned out very easy. Pending Add + sign or Pending Edit red check sign statuses on projects (below screenshot) of solution are git's statuses, this is very normal, and they will be disappeared after you "git add ." and "git commit -m 'messages'". Done!
After banging my head against a brick wall for 4 hours, it turned out I didn't want to delete the folders and files in the Source Control Explorer with the red X alongside them I had previously deleted, but merely toggle the Show/Hide Deleted Items button so it made them all disappear:
Highlight the adulterating red-crossed folder/file, and click the 2nd icon from the left in Source Controller menu that looks like an 'Xx'. For me, that's all I wanted to do. My offending files had actually been physically deleted from everywhere except from the documentary evidence that they had once been in the Source Controller. That sorted it for me.

Force TFS to detect changes

Seems like this should be something very simple, but I can't find how to do this...
I made a changes to several files spread within a repo by using a script that I wrote. Problem is TFS in its infinite wisdom does not think the files have changed. Aside from manually finding each file and clicking "checkout for editing" is there any way to tell TFS to just rescan everything and detect changes?
A Folder Compare (File->Source Control->Compare...) should do the trick. Select the top folder from where to start comparison, and select to compare with Latest Version. The result hould show files that are changed, and whether they are checked out or not.
TFS has a "Reconcile" command for this. See https://stackoverflow.com/a/22860674/932282 for a complete answer.
Local Workspace
You need to work with a local Workspace. Here's how to manage workspaces:
visualstudio.com: "Create and work with workspaces".
When adding or editing the workspace you click Advanced >> . Then you set Location: to Local.
Now when your script or anything else changes files outside Visual Studio, your workspace detects the changes automatically.
It also detects adds or deletes but you have to include them to your Pending Changes manually with the link under Excluded Changes
BUT BE CAREFUL. When adds or deletes get detected and you add them to your Pending Changes, the files aren't automatically included to your project. So you maybe check them in to TFS, but they aren't listed under the Solution Explorer.
Matt Burke has a fix for that problem:
mattburkdev.com: "Automatically Include All Files in Folder in Visual Studio"
To edit the Project file you rightclick your project, chosse Unload Project, then rightclick on it again and choose Edit. After you edited the project files save and close it. Then rightclick and chose Load Project.
But with that you also need to be careful, because the Project only searches for new files in these folders to include, when you load the project and not while you have the project open. So when some files get added outside Visual Studio, you just reload the project.
Server Workspace
But if you have to stick to a Server Workspace for some reason i got another trick for you:
FIRST:
Check out all Files that maybe have pending changes (better check out many files). Then go to Team Explorer -> Pending Changes and choose all files you just checked out. Then choose "undo changes". After this you get a message "Confirm Undo Checkout". This message ONLY pops up for the files, which actually HAVE changed! Press "NO" for each files or "No to All".
FINALLY: Under pending changes all files get removed from the list except the ones which have pending changes.
I hope I could help someone and you didn't have to search for this solution as long as I had to ^^
If any of your changes occured when you were offline, you can go to File > Source Control > Go Online, and all files will be checked for modification.
If none of the above work, you can also try to rebind your projects by going to File -> Source Control -> Advanced -> Change Source Control.
In Visual Studio 2015:
Source Control -> Advances -> Refresh Status
I had this problem a while age when i moved project from one pc to another.
the solution was to remove temporary files that TFS had created in solution folder.
Delete .vs and hidden $tf folder.
If no luck,on your local PC copy your solution folder to another, remove all files inside solution, get latest version from TFS server ,then from the copied folder just grab neccessary and edited files and put them back to solution folder (this will overwrite some files).
After all don't forget to check project mappings and if everything seems correct try right clicking on solution and 'Add to source control' option.
Dtsx file dropped in TFS folder was not being recognized.
On your Visual Studio (2015) home screen, click on the Team Foundation Server link. Make navigate to the correct branch.
On the window on the left side of the screen, navigate to the folder that contains your file. Expand the folder.
To the right of the folder you will see three dots. Click on those and then click on “ + Add File(s)”.
Choose “Upload Existing Files”. Then you can drag and drop your .dtsx files into the window and then click Okay.
Finally, you’ll have to do a ‘Fetch’ to add the files there. Then you need to do a ‘Pull’. Lastly, you can commit the change to remote branch.

How to see changes in local working copy in TFS?

I'm an experienced SVN user getting used to TFS at a new client site. The main problem I've had adjusting to the new tool is this - how can I get a listing of all files in my working copy that have changed from current/latest server revision, including added or deleted files?
Essentially, I'm looking for the TFS equivalent of an "svn diff". The "TF" command-line tool has a "diff" command which reports changed files but I can't find an option to report deleted or added files; this missing feature has resulted in a couple check-ins which (embarrassingly) broke the build.
Which version of TFS?
TFS2010 has a folder compare command, File > Source Control > Compare... (or in the Source Control Explorer, right-click on the project path you're interested in, and select Compare...).
Set up the Source path to be a folder on the server and the Target path to be a local folder in your workspace (or vice versa). Under View Options, select Show items that exist only in source path, Show items that exist only in target path and Show items that are different and click OK.
Is there any reason you can't use the Source Control Explorer?
If you right click on the folder, project or branch you can click Compare and you will see all files that have been deleted or added.
I usually do the following:
Open your Team Explorer tab in Visual Studio and click on Pending Changes.
There you will see your changed files.

Exclude from project, source control issue

I'm using team foundation server 2010 # work and home.
I want to exclude some element from the project build but still have them exist in Team Foundation Server 2010 source control. How do I achieve this?
Exclude From Project will delete the item.
Same problem here, only way to do this is manually edit project file :(
Please vote that this bug is important to fix
https://connect.microsoft.com/VisualStudio/feedback/details/573582/vs-2010-exclude-from-project-deleting-files-from-source-control
Workaround posted on Connect:
Open the csproj file in notepad and find the files that need to be
excluded and remove or comment the compile element for that file, and
any related designer and resx files.
Editing a project file and removing the references to the files you want to exclude would be the easiest solution.
Another solution would be to remove files from the project via UI, but only checkin changes in the project file and undo the delete operations.
In the future you can add files directly to the TFS folder in Team Explorer.
May I ask: why would you want to do that? As I commonly have a problem of files which are not bound to any project and have to be getted manually.
I work in a TFS environment, and if it were me? I'd just change the name of the file (instead of excluding it from the project), and check that in instead. Since your project is expecting that particular filename...it won't find it. We use this when we're developing prototypes or holding on to antiquated code for documentation purposes. Sorry VS is eating your stuff!
Kind Regards,
-sf
I think these steps should help you do what you are looking for.
To exclude an item from a deployment project:
In Solution Explorer, select the file you want to exclude.
On the Solution Explorer toolbar, select Properties.
In the Properties window, set the Exclude property to True.
And this page explains the actions for project files supported by VS 2010:
http://msdn.microsoft.com/en-us/library/0ebzhwsk.aspx
--- Edit ---
At work I tried 'Exclude From Project' in one of the files of a project we have in VS 2010, which is bound to a TFS 2010 server, and this action did not delete the item from TFS; the Source Control Explorer window shows the red delete mark next to the item, and the 'Pending Change' column says delete, but item is there. Right click the item in the Source Control Explorer window, one of the commands in the context menu that pops-up is 'Check In Pending changes' and another one is 'Shelve Pending changes'. Shelving enables you to set aside the pending changes.
The file is still in the local hard drive. If I do 'Include In Project' the item comes back to normal.

Using TFS source control - how to remove files

I am a lone developer, and I am now using TFS 2010, having until recently used VSS.
I have not found it easy to get any books for beginners to help me use this.
So I have now got my project in source control. But when I check in I get references to a number of files that I no longer use. How do I remove files from the TFS Source Control repository?
So in the example below, you can see lots of files from different projects that I do not want to see.
Click on the last icon that looks like a solution (.sln) file icon (last icon on the top vertical row). It's right next to the refresh icon and just above the "Comment" box. That should clear all non-related project files, and only show the files on your current project.
In Source Control Explorer in Visual Studio, simply right-click on files and folders and choose "Delete". Then right-click again and choose "Check-in pending changes".
You need to Destroy those files first, then only those files will get removed from source control.
You can't make any changes in those files - they remain in source control until you destroy them permanently from TFS.
For more info about how to destroy see TF Destroy command utility.
The files in your screenshot are (mostly) listed as add - they are not in TFS yet, so deleting them from TFS is not what you want. Rather you want to ignore them, though that can be tricky: How to ignore files/directories in TFS for avoiding them to go to central source repository?

Resources