TFS out of sync between local and remote - how to "re-sync"? - tfs

I have a Project on CodePlex which is using TFS and I am using the TFS Plugin for Visual Studio. Now I have copied this project and worked on another PC without TFS and done some refactoring. Foolishly, I have then just used copy/paste and manual text editing to merge my changes, expecting that TFS just picks up the changes.
Apparantly, that is not the case.
Here is a screenshot of my local directory:
My Local TFS http://img259.imageshack.us/img259/2897/tfslocal.jpg
Notice how some files are missing the lock symbol - those are missing. If you look at the current TFS Tree on Codeplex, there are some files which do not exist locally anymore, i.e. WikiPlexExtensions.cs in the main folder.
Is there any way to easily tell TFS to compare my local to the remote repository and pick up the changes? I could re-add the local files using "Exclude from local project" and re-adding them, and I could create the "deleted" files as empty files just to delete them, but if I can avoid the manual messing around that would be good as well :)

The easiest way is to exploit VS 2008's "online" feature. Basically you want to set your solution offline, then bring it online while connected to the proper Codeplex server. TFS should figure out the rest.
Feature overview: http://msdn.microsoft.com/en-us/teamsystem/bb898913.aspx
Tweaking the settings by hand: http://blogs.msdn.com/benryan/archive/2008/07/09/using-tfs-2008-power-tools-to-modify-server-s-offline-state.aspx

To compare local and server folders, you can check out TFS Power Tool. After installing it, you can bring up the source control explorer, right click on the server folder and then select 'Compare'. Folder difference window will display the differences. You can also right click on the differences to see available commands such as 'Get Latest' to update your local folder for example. Check out Bryan Harry's blog post on the power tool

I don't think there is an easy fix... What I've done in the past is back up those files that I have edited, then do a "Get Latest Version..." for the files I edited. This should change the files back to being read-only etc... Now, check out the files the regular way and paste the backups you had into the checked out files. Obviously this really only works when there are a couple of files you have edited.

TFS (in Visual Studio) has a "Reconcile" command for this, see Microsoft documentation, or this answer with steps.
BTW: This command may not haven been existing at time of original question, but this question came first when I was searching.

Related

How to check in mass changes into TFS

I have a situation where a developer made mass changes to a project outside of TFS (long story), and now we want to put those changes back into TFS (files added, removed, renamed).
Of course, TFS is not like Git; if I check out the project, then delete the files from the workspace and copy over the new files, TFS won't adapt to those changes.
I have discovered that I can do a Compare from File - Source Control, and that the Compare screen allows me to mark files as added/deleted. This helps, but is a slow process for a large project, and quite prone to human error.
So, my question is: Is there an automated way to get TFS to simply add all new files and remove all deleted ones?
I don't care about tracking history of renamed files--they can be
considered "removes" and "adds."
I have tried unbinding and rebinding the workspace; this did not work for me (or I didn't do it correctly).
I am using VS 2015, TFS 2015, and I have the TFS Power Tools.
If you are using a Local Workspace then you should be able to get latest on the workspace, then copy over all the new files in Windows Explorer which will generate pending changes and file adds.
If you go into Pending Changes in Team Explorer you will have lots of detected changes for new files etc. but you can promote them to included changes.
This isn't going to deal with file renames or deletions though so it might not be the best solution.
Alternatively you could use Reconcile Changes in Version Control
In Source Control Explorer, right-click a folder, and then click Compare.
In the Compare dialog box. select the folder versions to compare.
In the Folder Difference window, right-click the folder or file you want to reconcile, and click Reconcile.
This will allow you to choose what to add or change to version control
You might try using tfpt online. I would add the /adds /deletes /diff /recursive flags as well.
I think in almost any case you will have some conflicts/manual work to do here.
There is a blog post on a possibly similar situation that used tfpt online as well: Discover File Changes Made Outside of Visual Studio
Since I did not get to try the above suggestions, I'll post the workaround I did, in case it helps anybody else. Hopefully, the above suggestions are better than what I ended up doing.
Make sure nothing is checked out
Open solution
Team - Go Offline
Close solution
Windows Explorer - Copy latest source folder into the current source folder (Windows Explorer will do a Merge).
VS - Open solutin, select solution file
File - Source Control - Advanced - Change Source Control
if you get a message about unloaded projects, make sure all projects loaded. Click "Reload" on those that didn't.
Shift to select all project, click Bind
Do a Compare in Source Control Explorer. Manually add all new files. Manually delete all deleted files. Frown.

Visual Studio 2015 - Merge tool button missing

I'm having problems with merge tool in Visual Studio 2015. I didn't need the merge tool for the longest time, I haven't used it for couple of months. Now when I need it I can't find it. I was trying to google and find an answer, checking VS settings but with no success. I can only see buttons 'Overwrite Local File or Folder' and 'Keep Local File Contents'. When I press Compare button, I see diff tool but I'm not able to accept changes (check buttons are missing).
What am I doing wrong? How can I merge two files?
Please navigate to files in source control
Right click on file/folder you want to branch>>Merge
Full list of other solutions.
This is because these files in your local folder are not been tracked by TFS Version Control. For example, you added a file "readme.txt" in you local folder and hadn't check-in them into version control. Another people in your team also added this file in the same relative path and checked it into version control. Now, when you get the latest version or check in your changes, you will get the behavior as your screenshot. A similar question can be found here: TFS Conflict Type: Writable File - A writable file by same name exists locally
It's doing exactly the same things in Visual Studio 2017.
If you had a problem in workspace and you rollback it from a save, you can have the same issue.
You need to rebind some of the project by yourself first like the asked question here : Re etablish TFS source control bindings, then if all is going well you will see the button.
If it's not working, try to use external merge tool which will allow you to edit thoses files.

TFS - What happens if I delete a workspace?

I started work a lone developer last year and I found VSS is no longer a good option for source control so I decided to use TFS 2010 instead.
I have had to learn everything from a book - of which there are few.
I am currently creating a new build and in my workspaces I see a have 4. I want to delete one of them and rename another.
However I do not know what the consequences of doing this are. If I delete a workspace, will that remove the associated files under source control? How do I check which files these are? What happens if I change a status from active to cloaked?
As you can see, I am a beginner in all this.
Workspaces are only a mapping from SourceSontrol folders onto your local file system. Also workspace contains information about versions of the files you have locally, so when you hit 'Get Latest Version' only recent changes are sent from server to you, not the whole files. Information on what files are checked out is stored in workspace too, so if you have pending changes in the workspace and delete it then there'll be a bit of a challenge to check these changes in. Renaming of the workspace will not break anything as far as I know.
Article An introduction to TFS Workspaces may be interesting to you.
Like the others have said, the workspace only says what local files you have checked out, and the status, etc. Workspaces are pretty granulal (i.e. per user and per machine) so you could have mutliple workspaces with the same username in the same project. E.g. if you have a copy of Visual Studio at work and one at home, you could have different files checked out and you wouldn't run into any conflicts like you would have in VSS or something based on VSS Like like VSSConnect.
We've had a couple of people leave out project and have had to go in and remove their workspaces after the fact. This hasn't been a big deal in terms of any code losses but if you don't have access to the machine anymore you will have to use the TFS tools.
Try TFS Sidekicks, it provides a nice GUI to manage all the nitty-gritty back-end stuff in TFS

Why doesn't TFS get latest get the latest?

Why Why WHY doesn't TFS's get latest work consistently?
You would have thought that feature would have been tested thoroughly.
What I have to do is, get specific version, then check both overwrite writetable files + overwrite all files.
Is my local setup messed up or you do this also?
TFS redefined what "Get Latest" does. In TFS terms, Get Latest means get the latest version of the files, but ignore the ones that the server thinks is already in your workspace. Which to me and just about everyone else on the planet is wrong.
See this link: http://blogs.microsoft.co.il/blogs/srlteam/archive/2009/04/13/how-get-latest-version-really-works.aspx
The only way to get it to do what you want is to Get Specific Version, then check both of the "Overwrite ..." boxes.
Sometimes Get specific version even checking both checkboxes won't get you the latest file. You've probably made a change to a file, and want to undo those changes by re-getting the latest version. Well... that's what Undo pending changes is for and not the purpose of Get specific version.
If in doubt:
undo pending check in on the file(s)
do a compare afterwards to make sure your file matches the expected version
run a recursive 'compare' on your whole project afterwards to see what else is different
keep an eye on pending changes window and sometimes you may need to check 'take server version' to resolve an incompatible pending change
And this one's my favorite that I just discovered :
keep an eye out in the the Output window for messages such as this :
Warning - Unable to refresh R:\TFS-PROJECTS\www.example.com\ExampleMVC\Example MVC\Example MVC.csproj because you have a pending edit.
This critical message appears in the output window. No other notifications!
Nothing in pending changes and no other dialog message telling you that the file you just requested explicitly was not retrieved! And yes - you resolve this by just running Undo pending changes and getting the file.
TFS, like some other source control providers, such as Perforce, do this, as the system knows what the last version you successfully got was, so get latest turns into "get changes since x". If you play by its rules and actually check things out before editing them, you don't confuse matters, and "get latest" really does as it says.
As you've seen, you can force it to reassess everything, which has a much greater bandwidth usage, but behaves closer to how SourceSafe used to.
It's hard to respond to a statement without examples of how it's not working, but it's crucial to understand that TFVC (in "Server Workspace" mode, which was the mechanism prior to TFS 2012) does not examine the state of your local filesystem. TFVC Server Workspaces are a "checkout-edit-checkin" type of system where this is by-design, an intentional decision made to massively reduce the amount of file I/O required to determine the state of your workspace. Instead, the workspace information is saved on the server.
This allows TFVC Server Workspaces to scale to very large codebases very efficiently. If you are in a multi-gigabyte code base (like Visual Studio or the Windows source tree) then your client does not need to scan your local filesystem, looking for files that may have changed, because the contract you have with TFS is that you will explicitly check a file out when you want to edit it.
You are expected to not mark a file as write-only and change it without explicitly checking it out first. If you go down this route, then the server does not know that you have made changes to your file, and performing a "Get Latest" operation will not update your local workspace, because you haven't told the server that you've made changes.
If you do subvert this mechanism then you can use the tfpt reconcile command to examine your local workspace for changes that you have made locally.
If you find yourself using "Get Specific Version" and selecting the "force" and "overwrite" options, then it is very likely that you are in the habit of bypassing all of the enforcements that TFS has implemented to keep you from hurting yourself, and you should probably consider TFVC Local Workspaces.
TFVC Local Workspaces provide an "edit-merge-commit" type of version control system, which means that you do not need to explicitly check files out before editing them and they are not read-only on-disk. Instead, you simply need to edit the file, and your client will scan the filesystem, notice the change, and present this as a pending change.
TFVC Local Workspaces are recommended for small projects that do not require fine-grained permissions control, since they present a much nicer workflow. You are not required to be online, and you do not have to explicitly check files out before editing them.
TFVC Local Workspaces are the default in TFS 2012, and if they are not enabled for you, then you should ask your server administrator. (Organizations with very large codebases or strict auditing requirements may disable TFVC Local Workspaces.)
Eric Sink's excellent book Version Control By Example outlines the differences between checkout-edit-checkin and edit-merge-commit systems and when one is more appropriate than the other.
The Professional Team Foundation Server 2013 book also provides excellent information about the differences between TFVC Server Workspaces and TFVC Local Workspaces. The MSDN documentation and blogs also provide detailed information:
Decide between using a local or a server workspace
Server workspaces vs. local workspaces
Team Foundation Server – Trying to understand Server versus Local Workspaces
Team Foundation Server (TFS) keeps track of its local copy in a hidden directory called $TF.When you issue the "get Latest Version", TFS looks into this folder and see weather I have the latest copy or not. If it does it will not download the latest copy. It does not matter if you have the original file or not. In fact you might have deleted the entire folder (as in my case) and TFS won't fetch the latest copy because it does not look into the actual file but the hidden directory where it records changes. The flaw with this design is, anything done outside the system will not be recorded in TFS. For example, you may go into Windows explorer, delete a folder or file and TFS wont recognize it. It will be totally blind. At least I would expect there Windows would not let you delete this file but it does!
One way to enforce the latest copy is to delete the hidden $TF folder manually. To do that, go to command prompt and navigate to the root folder where you project was checked out and issue this command
rd/s $tf // remove $TF folder and everything inside it
If you want to just check the hidden folder, you can do it using
dir /ah // display hidden files and folders
Note: If you do it, the tf will think you do not have any local copy even though you have it in files and it will sync up everything again.
Caution: Use this method at your own risk. Please do not use it on critical work.
"Get latest version" by default will only download the files that have changed on the server since the last time you ran "Get latest version". TFS keeps track of the files you download so it doesn't spend time downloading the same version of the files again. If you are modifying the files outside of Visual Studio, this can cause the consistency problems it sounds like you are seeing.
Unfortunately, there has to be one or more bugs in TFS 2008, since this problem regularly crop up on developer machines and build servers where I work as well.
I can do Get Latest, I can see in the history list of the project that there have been commits after I last did a Get Latest, I have not touched the files on disk in any way, but after the "Get Latest" function has completed, when I check the TFS tab, some of the files still says that they're not the latest version.
Obviously TFS is able to determine that I have old files locally, since the list says so. Yet, Get Latest fails to do that, get the latest version. If I do what you did, use the Get Specific version, and check the two checkboxes at the bottom of the dialog, then the files are retrieved.
We changed our build servers to always use the Get Specific version type of function instead, so this part now works, but since our build server (TeamCity) also relies on checking if there have been changes to the files in order to kick off a build, sometimes it lapses into a "nothing changed, nothing to see here, move along" mode and does nothing until we forcibly run the build configuration.
Note that I have experienced this problem on a machine that is never touched, except for get latest + build, both manually, so there's nothing tampering with the files. It's just TFS getting confused.
One time this cropped up I verified that the files on disk was indeed binary identical to the version previously retrieved, so no manual tampering had been done with the files.
Also, I fail to see how TFS can "know" whether files have changed on disk or not without actually looking at the contents. If one part of TFS can see that the files are indeed not the latest version, then the Get Latest version should absolutely be able to get the latest version. This in reference to comments to other answers here.
It might because you are login TFS as the same user, and the workspace name (based on machine name by default) is also the same, so TFS thinks your are on the same machine and same workspace, thus you already have the latest version of the files, so it wont get them for you.
try rename your machine, and create a new workspace as a new machine.
Go with right click: Advanced > Get Specific Version. Select "Letest Version" and now, important, mark two checks:
The checks are:
Overwrite writeable files that are not checked
Overwrite all files even if the local version matches the specified version
WHen I run into this problem with it not getting latest and version mismatches I first do a "Get Specific Version" set it to changeset and put in 1. This will then remove all the files from your local workspace (for that project, folder, file, etc) and it will also have TFS update so that it knows you now have NO VERSION DOWNLOADED. You can then do a "Get Latest" and viola, you will actually have the latest
I had the same issue with Visual Studio 2012. No matter what I did, it didn't get the code from TFS source control.
In my case, the cause was mappings a folder + subfolder from the source control separately but to the same tree in my local HD.
The solution was removing the subfolder mapping using the "manage workspaces" window.
Most of the issues I've seen with developers complaining that Get Latest doesn't do what they expect stem from the fact that they're performing a Get Latest from Solution Explorer rather than from Source Control Explorer. Solution Explorer only gets the files that are part of the solution and ignores anything that may be required by files within the solution, and therefore part of source control, whereas Source Control explorer compares your local workspace against the repository on the server to determine which files are needed.
It could happen when you use TFS from two different machines with the same account, if so you should compare to see changed files and check out them then get latest then undo pending changes to remove checkout
This worked for me:
1. Exit Visual Studio
2. Open a command window and navigate to the folder: "%localappdata%\Local\Microsoft\Team Foundation\"
3. Navigate to the sub folders for every version and delete the sub folder "cache" and its contents
4. Restart Visual Studio and connect to TFS.
5. Test the Get Latest Version.
In my case, Get specific version, even checking both check boxes and undoing all pending changes didn't work.
Checked the work spaces. Edit current workspace. Check all paths.
The solution path was incorrect and was pointing to a deleted folder.
Fixed the path and get latest worked fine.
Every time this happens to me (so far) is because I have local edits pending on the .csproj project file. That file seems to keep a list of all the files included in the project. Any new files added by somebody else are "not downloaded" because they are not in my locally edited (now stale) project file. To get all the files I first have to undo pending changes to the .csproj file first then "get all". I do not have to undo other changes I have made, but I may have to go back and include my new files again (and then the next guy gets the same problem when he tries to "get all"...)
It seems to me there is some fundamental kludginess when multiple people are adding new files at the same time.
(this is in .Net Framework projects, maybe the other frameworks like Core behave differently)
just want to add TFS MSBuild does not support special characters on folders i.e. "#"
i had experienced in the past where one of our project folders named as External#Project1
we created a TFS Build definition to run a custom msbuild file then the workspace folder is not getting any contents at the External#Project1 folder during workspace get latest. It seems that tfs get is failing but does not show any error.
after some trial and error and renaming the folder to _Project1. voila we got files on the the folder (_Project1).
Tool:
TFS Power Tools
Source:
http://dennymichael.net/2013/03/19/tfs-scorch/
Command:
tfpt scorch /recursive /deletes C:\LocationOfWorkspaceOrFolder
This will bring up a dialog box that will ask you to Delete or Download a list of files. Select or Unselect the files accordingly and press ok. Appearance in Grid (CheckBox, FileName, FileAction, FilePath)
Cause:
TFS will only compare against items in the workspace. If alterations were made outside of the workspace TFS will be unaware of them.
Hopefully someone finds this useful. I found this post after deleting a handful of folders in varying locations. Not remembering which folders I deleted excluded the usual Force Get/Replace option I would have used.
I encountered the same problem:
My development server was corrupted and restored, but the information restored was from a few days ago.
TFS was updated that all the files are up to date, but in practice my files were correct a few days ago!
Nothing I did helped. get latest did not get the latest version.
At the end I got specific varision from a month ago. my files were updated accordingly, and then I did get latest.
And it worked. the files have been updated.

Can TFS Pending Changes show files that are truly changed like SourceGear Vault?

I have been using SourceGear vault for some personal projects and Team Foundation Server for work projects. One thing TFS is missing is a simple feature that Vault has on its check in dialog window.
In the Vault client, you can see if the checked out file changed from the previous version checked in. Here is a screen shot. Notice the column "Details"? That tells you there is a difference. The way this is super helpful is if you have to check out a entire project because you are going to do code re-generation. I'll check out my class library project and then regenerate my CodeSmith templates. Doing this may result in just a few specific files from changing. When I view the pending check-in screen, I see the files that really changed and I can compare to see the impact.
SO... can TFS do this? Maybe there is a 3rd-party tool that will do it for me? Is there a TFS SDK or PowerTool that I have to get. Anyone want to build it?
Select all the files in "Pending changes" window and activate the context menu. Then click "Undo..." > "Undo Changes" > "No to All".
The files without changes will be rolled back.
Per this page, you can run this command from the Visual Studio Command Prompt.
tfpt uu /noget /r *
You'll need to have TFS Power Tools installed for this to work. Also, make sure you browse to the root of your mapped folder within the command prompt (ie - C:\TFS for example).
TFS Power Tools links (if you don't already have it)
TFS Power Tools for 2010
TFS Power Tools for 2012
There is no need to undo the unchanged files, as TFS will notice they're unchanged upon checkin and will only associate the truly changed files. Any files checked out but unchanged are reverted to their last known checked in version and will not be associated with your checkin. It is impossible in TFS (though not very clearly documented) to check in an unchanged file. It will always revert to the previous version if there are no changes.
You can quickly undo your unchanged files by calling 'tfpt.exe uu /r' from the command line (you need to have the Team Foundation Power tools for this) or by using the "Undo unchanged" button in the Pending changes window. This removed any items from the list that are unchanged immediately. So that you can see exactly what you're checking in.
Though it might be that this option is added by the Team Foundation Power Tools or the TFS Source Control Explorer Extensions (which are a must have for every TFS user anyways).
See also:
https://stackoverflow.com/a/2100981/736079
https://stackoverflow.com/a/6387656/736079
https://jessehouwing.net/vsts-tfs-why-i-like-them/
I don't like answering my own questions, but it looks like there might not be a real Microsoft solution out there. For me, this is how I handle the problem at the office using Visual Studio.
Before I re-generate the business objects, I make a copy of the entire folder structure
I check out the entire project or the root generated folder
I start the code generator. Sometimes, I know exactly what is changing, but other times, I might make a lot of changes and I don't want to miss anything. My code generator at work also generates all the SQL files needed to DROP / CREATE stored procedures.
Using SourceGear DiffMerge, I compare the folders of the just generated and the previously backed up folder.
This is pretty time consuming. I never thought of it as a problem until I saw Vault identifying that a file was different on disk from the repository.
Maybe you all can say how you do code generation / regeneration when working with a source control repository.
I work in a corporate development environment where many developers may be working on the same file, and we have TFS as our source control as well. In our document of Best Practices for TFS, we really discourage checking out files that the developers don't intend on changing, that way we naturally exclude files without differences when submitting a changeset.
To answer your question, I normally just look at the "Pending Changes" window and run a Compare on the "changed" files that I'm unsure of--the Compare tool should immediately tell you if your local copy is the same as the server copy. Unfortunately, there's no real workaround other than what I suggested, but I don't see the scenario where I absolutely must check out an entire project branch for editing.

Resources