In Visual Studio 2013 Update 3, I accidentally checked in a not-compiling, work-in-progress changeset that I intended to shelve in order for a co-worker to take. I rolled back the change set right away. Bad me.
Is there a way to recover that bad/rolled-back changeset as a Pending Changes so that I (or my co-worker) may continue to work on it? I didn't see anything in the UI and had to manually pull out each file and construct the pending changes by hand. It was only 20 minutes of work to code it originally, so not that big a deal (it was my error) but I'm curious if there was a better way.
As was said in the comments, you can "rollback the rollback". I do it all the time. Just find the rollback changeset in history, and roll that back, and it will get you your half-finished changes into your local workspace, so you can continue working on them and check them in when done.
Related
I work in many ASP.NET projects at once in VS 2019; I use TFS (without git), with a local workspace. As a way to make sure I have a "shelveset as a backup" in case I could lose my local work (hd fault, robbery, sticky fingers, lazy mind...), I am thinking of following these steps:
At the end of the day, I create a shelveset named with my username, preserving local changes.
The next morning, I continue working ignoring my first shelveset; Again, at the end of the day, I create a SECOND shelveset with my username+"2". When I'm sure it has been created without errors, I proceed to delete the first shelveset.
And the next morning I do the same, and so on...
What do you think guys, is it a good approach to make sure I will not lose any local changes in case of disaster?
Shelving is a simple way of storing your changed files. Your process is a bit convoluted. I'd simply run:
tf vc shelve /replace "daily backup" /noprompt /recursive
The command happens transactionally, so when it succeeds is replaced the old shelveset. If it fails, your previous changes will remain in tact.
An even better approach would be to craft smaller changes and to check in more often. That way your changes aren't just store on the server, but also integrated with your peers.
Visual Studio also has a built-in UI to suspend your changes. Open the My Work pael in Team Explorer and hit the Suspend work option. It will create a shelveset in the background.
The next day, simply Resume work:
Is there a way in TFS to edit files and then (maybe) merge them later without having to do a checkout? Basically edit then only touch source control when I decide to update to the server, not in advance.
Or has 5 years of Mercurial and Git just led to me getting confused about how TFS works and what I want is not possible and doesn't matter because "checkout" is not exclusive. (most likely option? :-) )
(I have been here but that does not solve my issue)
There are ways to cheat that, but there's no good reason to do so. When you check out code from TFS, you're getting a local copy to work with. When you check it back in, it creates a changeset, which is an atomic commit of your changes to the source code repository. If you don't want to check it in, and go off and do something else, you can create a shelveset, which can be named and unshelved whenever you're ready.
Similarly, if you use Gated check-ins, that process creates a shelveset automatically and sends that for a validation build. If it fails, you just make changes to your shelveset and try again. If it succeeds, it checks a changeset into the source repository. It helps prevent checking in breaking changes.
I rolled back a changeset. Now I need to check out the changeset that was rolled back with 'actualized' pending changes. So like everything is before the commit of the changes.
When I get specific version with files override I see nothing in pending changes window.
How can I get the state I need? Is it possible?
After doing the "Get Specific version" you need to check out every file in the changeset manually (right-click, check-out). Be sure that you have the "Get latest on checkout" turned off.
After that perform a get latest, which will prompt you to merge. This is going to be a more tricky merge, since Visual Studio will assume that the newer version is what you want. When you're satisfied, check in the code.
Alternatively start with the same steps as the first solution, but instead of immediately doing a get-latest, you can create a shelfset after you've checked out each file and then perform a get latest. When you're on the target version, unshelf your changes, resolve any conflicts and check them back in.
Another trick you could apply is to find the changeset number that contains the rolled back changes. Since this checkin is a compensating checkin, you might also be able to re-do the changes by rolling back that compensating changeset. I tried this in a local workspace and it works. Again you might need to go through a merge and it's hard to tell exactly which changes to pick.
My best advice on this is: try not to get into this situation :).
I'm finding that a number of my changes are being 'lost' when our contractor performs a check-in.
The general process is as follows:
I perform some bug analysis and implement a fix.
I then check-in my code.
The contractor performs a check-out/check-in at a later date.
The changes from the previous changeset (my changes) are lost.
In my view, this is pretty unacceptable, particularly when I'm dealing with application-breaking regressions introduced since the last build.
This has happened at least twice now, and the only thing I can think of is that the contractor is failing to ensure that he has the latest changeset at check-out. Our repo does not allow multiple check-out, and forces get latest on checkout, which makes things so weird (seeing as we both should be working with Server workspaces).
Could there be any other cause of this problem? I don't want to take my concerns to my line manager without being sure I've covered all bases.
Get Latest item on check out is set in the client and not in the repo, which means that your contractor may still be able to checkout the wrong version. They should get merge conflicts upon doing so, but that depends on where they edit (and how they manage such conflicts).
I've seen TFS lose changes this way. I have yesterday gone to a client site, made changes, checked in, today come back to my office, got the changes (assuming it will merge with my local changes like it usually does), gone to check in just now and I can see in the diff that it's wiped out the client-site changes (obviously ignoring the merge locally). I checked in just to confirm what I was seeing and yes there was no resolve conflict needed, TFS thought everything was ok, but my modified local file just blatantly overwrote the modified version in TFS effectively discarding the whole client-site change (just like if I'd chosen resolve conflict keep mine - however it never asked me about the conflict or suggested that there was one, just silently lost it)
If you eye-ball the changes before committing you can see that the changes you are making are more than you thought - i.e. the client site changes are effectively being removed and will show as differences - however it's easy to miss this when you are doing it a lot.
I had previously thought to blame coworkers when they skip out my changes this way, but now I've actually seen myself do this to myself I realise the tool is deficient. Hard to believe but there is obviously something wrong with the way it merges your locally changed file against the 'get latest'. I'm using a cloud TFS with a flaky network connection sometimes - I'm told this contributes to the issue.
Here's the part I get: When you shelve in TFS, it makes a server copy of the changes so they are not lost, but does not check them into the source code trunk/branch you are working on.
Question: Under what circumstances would you use the "unshelve" feature? Does it mean it will remove the shelveset from the TFS server? Can you do a get from a shelveset? Or is it really just a diff description between the shelveset and the "real" source code?
Unshelving is how you restore the shelveset to your machine so you can keep working on it. It doesn't change the shelveset on the server (to do that you need to shelve things again and use the same shelveset name).
One example for how I use it is to move changes between machines while I'm working on them. I'll shelve it on my desktop machine, then unshelve it on the laptop and then continue working on the laptop.
You can also use it to share changes with someone (for code reviews or other reasons). You shelve your changes, then the other person can go and unshelve it to see what you've done.
Unshelving doesn't actually change the shelveset or anything else on the server. It's just a get operation.
Herms is spot on. Read his answer.
One important caveat: if you've done a Get since the shelveset was created, Unshelve will only rollback the local version of files contained in the shelveset. Thus, it's quite likely you'll have an inconsistent workspace.
A good practice is to always re-run Get after you Unshelve. This ensures you don't waste time on phantom build errors that are actually just side effects of being in a half-new/half-old state. It will also require you to resolve any conflicts between the shelveset contents and the latest server revisions proactively, instead of only discovering them # Checkin time.
I use shelve to back up code-in-progress, just on the off chance my hard drive crashes or whatnot. I don't even have to worry about the code building, never mind working, since the work won't be seen by any other developers on my team (unless they go looking for it).
Unshelve pends the changes back in your workspace. Removing the shelveset from the server is a Delete.
Following on to what Richard Berg said, the power tools' version of unshelve actually includes a get and resolve.