TFS: How to merge only changes on my shelve, without overwriting local copy enterily - tfs

I'm trying to find a way to merge shelve changes with the latest version I have locally without overwriting my local files with those of the shelve.
That is, I have a shelve from date 0, on date 1 some changes were done in the tree, on date 2 I do a Get Latest Version, then when applying the shelve, changes of date 1 get lost.
No merge conflict between changes in date 1 and those of my shelve.
Ideas? Thanks!

Finally, what I ended up doing was to
1) "get specific version" to the date when changeset was taken
2) "get latest version".
That way, TFS merges latest version with changed local files. (The other way around -what I was looking for- seems not possible).

Two options spring to mind:
(Advice: Before you start, back up your code, in case there is anything in there that isn't safely stored on the server or in a shelve set!)
If you unshelve first, you will end up with locks on the shelved (0) files.
Then GLV to get the (1) files. All the files you have locked will be merge conflicts, which you can then resolve, test, and check in as normal.
Get the shelved code and copy it to another folder on your hard drive. Then GLV the latest server code. Check out the files you have changed (or easier, the root folder), and then manually merge the two sets of sources. You can then "undo check out" to get rid of the unchanged files (say "no" to the "discard your changes" question and it'll keep locks only on changed files) and after testing that your code works, check in the resulting changed files.

You need another Workspace, that is a local folder were your working copy resides (Yes, you can have more than one).
With a fresh Workspace with no changes on it, you could recover your shelve there, do the check-in, and have your original workspace untouched. Optionally, you could delete the alternative Workspace, or keep it for these kind of maintenance tasks.
For creating a new Workspace, just open the Source Control Explorer and open the Workspace combo-box on the upper toolbar. Select Manage Workspaces and create a new one from there.

Related

Synchronise TFS database with workspaces (put not get)

We had a corruption in our TFS database and had to restore it to a previous time. This caused our workspaces to be 'in the future' and our TFS server to be 'in the past'. I tried to do a check in so that VS would update TFS to the latest version but it only checked in the files I had modified since the last check in.
Since the last check-in was after the last backup and is now gone, how do I synchronise TFS so that it has the lastest version which is on my machine?
you will need to perform "add items to folder" action instead of "check in pending changes"
There is probably an easier way but in the past this has worked fairly well.
Make a full copy of your local
Do a complete get latest/force/overwrite
Checkout the entire folder
Overwrite the working folder with your copy
Use a diff tool (or whatever method you want) to do the manual adds/deletes to TFS that won't come in when you copy
Check in the entire folder (only the changed files will mark in history) - a comment like "fixing corruption" is helpful for the future
Files will all be in TFS and up to date. Obviously history/labels/merges/etc are gone.

Shelving/Unshelving: how does it work regarding file contents and version specs

As an experienced SVN user and TFS beginner, I have some questions about the Shelving/Unshelving process. Hopefully some experienced user can help me a bit with them.
My intent is to understand how shelving/unshelving works regarding file contents and versionspecs. To do that, I will present some concrete situations.
I have my (remote) workspace mapping updated to versionspec (== svn revision) X, and I do some local changes, and then shelve them.
Can I unshelve them in a different, empty workspace mapping (before doing any 'get')?
Can I unshelve them in a different workspace mapping, which is pointing to versionspec X-2 (no relevant changes in the code between these to versionspecs)?
Can I unshelve them in a different workspace mapping, which is pointing to versionspec X+2 (no relevant changes in the code between these to versionspecs)?
Can I unshelve them in a different workspace mapping, which is pointing to a different version spec which has 'relevant changes' in the affected files/lines?
Can I unshelve them in a different workspace mapping, pointing to versionspec X+2, without 'relevant changes' at X+2, but with relevant changes that happened at X+1 (imagine, a line that is removed at X+1, but appears again at X+2) ?
What is the expected behaviour in those cases. Would i get any errors/conflicts?
Would I encounter any difference if I used a local workspace instead of a server one?
No, you can't unshelve in any of this situations! Imagine shelve is a way to keep your work saved when you get up of your desk at 18:00 PM at company on friday and put in a drawer... And get back to the table on monday! Because any item is shelved keeping the address on source control. If you want move to another address, you'll unshelved, and move the item later.
There are some terminology issues going on here. A workspace mapping is simply a list of local paths and the server paths that you want to download to them. A workspace mapping is not "empty" before you do a get; a workspace mapping would be empty if and only if you did not have any mappings from server paths to local paths.
Yes. If you set up a new workspace but do not do a get, you can unshelve a shelveset. This will result in you only having the files shelved, and no otehrs.
Yes. If you had some file Foo.cs at version 8, and you unshelve Foo.cs that was changed at version 6, then now you have Foo.cs at version 6 with the shelved changes. Other files that were not in the shelveset will stay at whatever version they were at, shelving and unshelving do not affect them.
See #2.
In general, no. You can use the TFS Power Tools to do an "unshelve /merge".
Yes. Again, this would simply bring your file back to the version that it was shelved at. If there are changes on the server, then you need to do a Get Latest to merge the local (unshelved) changes with the changes on the server. This mimics the workflow if you had never shelved in the first place.

Delete Local Folder in TFS

I'm part of a large project mapped from TFS, within that project there is a folder which I have finished working on. I don't want that folder anymore so I'd like to delete my local copy. The problem is that TFS wants to mirror the change and delete the folder from source control, I don't want to remove it from TFS.
The only way I can find to do this is to unmap the workspace, and then go through and get all the other folders I need to work on.
Is there anyway I can just delete that folder locally?
This is an older post, but since the only given answer seems "not entirely correct" to me I'd like to answer anyway:
I blogged about this (in german) here: blog.nils-andresen.de
If you have a local copy, that you want to un-get or un-download like this:
simply right-click the folder and then click "Get Specific Version" or "Advanced > Get Specific Version" and specify Changeset 1.
Here's why from Martin Woodward's TFS Top Tips:
...if you do a "Get Specific Version..." on the files, and select Changeset 1, the files will be deleted locally and the server will know this. The color of the file in the Source Control explorer will go from black to gray and will have the phrase "Not downloaded" in the latest column.
Changeset 1 is a special changeset on your Team Foundation Server instance. It was created as part of the setup routine and only contains one thing - the root node ($/) in your source control tree. If you do a get for Changeset 1 on any actual files then they will not exist at that point in time on the system so will be deleted locally and the server will know this.
When the process is complete the "Latest"-column will show "not downloaded".
After that any remaining files in the filesystem can safely be removed.
You can cloak the folder in your local workspace.
By setting the working folder status to Cloaked, you can specify that a local folder should not copy files from the server when you perform a Get operation. You might choose to do this to conserve space on your local disk. If you later decide that you need to get files in those cloaked folders, you must change the status to Active and then perform a Get operation.

Renaming folders in TFS 2010

What's the proper way (sequence of steps) to rename a folder in TFS? I tried doing it locally then commit but it's not working. I think you prob have to do it from TFS (server-side) instead right? But then if you do that and get latest then I guess it'll just update your folder locally and hopefully you don't have any other conflicts?
Open Source Control Explorer, mark your module, press F2 & enter the new name.
Module will appear in your Pending Changes window with Change type "rename".
Suppose you had a module named test.txt which participated in 3 changesets. It then gets renamed into itsatest.txt When I get History for file itsatest.txt I get this:
In my hard drive the test.txt doesn't exist after the rename.
The same principle works with folders as well.
EDIT after comment
Problem is I did all this renaming locally on my file system...I don't
want to lose all these changes because I also changed namespaces in
code, etc
I see. One way to proceed is to copy the entire directory somewhere out of your workspace. Then delete it from your workspace and retake it from source control with 'Get specific version' and 'Overwrite all files even if the local version matches the specified version'. Proceed with the rename & checkin.
Perform a directory compare between your locally stored dir & the one you 've just renamed. All your changed files should appear. Check them out & copy-paste them manually into your workspace.This should take care of the situation.
I'm pretty sure I remember another TFS SO post, where the recommendation was 'never mix pending changes with pending renames' - can't seem to find it ATM...

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.

Resources