• No results found

History, compare, and rollback

In document Introduction to Source Control --- (Page 28-36)

In this task, you’ll use three related features of source control in Visual Studio: history, compare, and rollback.

History allows you to search, filter, and view the past checkins of a given file. For example, you may see unexpected behavior in the current codebase and want to understand what changes have been made that might have caused it. History is also a great way to know who to blame if the build breaks!

Compare provides an easy way to see the differences between the files. When you compare files, Visual Studio will infer the adds, deletes, and changes at a per-line level. When possible, it will even highlight the specific part of a line that has changed.

Rollback enables you to roll back a changeset in order to remove their changes from the codebase.

While that changeset still remains in the history, you can easily undo the effects by accessing the earlier version and checking it back in as the latest.

1. In MainWindow.xaml, change the background color of the window to green. You’ll need to allow the file to be checked out along the way.

2. Press F5 to run the application. The background is now green. Close when satisfied.

3. In Solution Explorer, right-click MainWindow.xaml and select Check In….

4. In Team Explorer, type “Changed background to green” and click Check In.

5. After the check in completes, right-click within the MainWindow.xaml file open in the XAML editor and select Source Control | View History to bring up the history view.

6. The history view provides a list of all the checkins for this file. If you right-click on the second item, you’ll see a lot of interesting options that allow you to see more details, compare with other versions, get this specific version, or to even roll back the entire changeset. Select View.

7. Visual Studio will download that specific version of the file, which you can see is saved to a temporary path and is read-only (the lock icon next to the path). You’ll also notice that the background of the window is blue, confirming that it’s the previously checked-in version you wanted.

8. Close the file.

9. In the history view, right-click the second item again and select Compare….

10. Visual Studio downloads the requested version and compares it to the one in your current

workspace, opening it in a diff (“differences”) window. On the right-hand side you can see the red marker indicating where the earlier file has had lines changed or removed. The green marker indicates where the later version has changed or added lines. If you look closely at the source files, you can see that the “Blue” and “Green” text has been subtly highlighted because that is the specific change detected in that line.

11. Close the diff window.

12. When you selected View earlier, it was noted that the file was downloaded to a temporary location and set to read-only. However, sometimes you’ll want to pull that version into your project to work with it directly. To do this, simply right-click that version in the history view and select Get This Version.

13. Press F5 to run the application (or Debug | Start Debugging from the main menu). The background is now blue because the earlier version was downloaded and compiled into this build.

Now that you’ve confirmed that this is the version you prefer to the green background, you can continue working with this file and eventually check it in to become the latest version. However, sometimes it’s not as easy as dealing with a single file, so it’s more effective to use the rollback feature.

When you roll back a changeset, you’re effectively getting the latest version, but ignoring that changeset and anything that came after it. One downside to this approach is that it rolls back the entire changeset, so you need to pay special attention that you’re not overwriting changes you want to keep elsewhere.

Note: Rolling back doesn’t actually delete the changeset. Changesets are permanent. Instead, a rollback pulls down the specified version and treats any changed files like a pending change you’ll need to check in later.

14. In the History - MainWindow.xaml window, right-click the most recent changeset and select Get This Version. Ordinarily you wouldn’t need to do this step, but the current state of your workspace happens to be exactly the same as what it will be after the upcoming rollback. As a result, the rollback would fail because there would be no changes to make.

15. Right-click the latest changeset (the one where you changed the background to green) and select Rollback Entire Changeset. If Visual Studio asks if you’d like to reload files that have changed, click Yes to All. Remember that the version you select is being rolled back, so it’s actually the version prior to that one that will be downloaded.

16. In Solution Explorer, note that MainWindow.xaml is now treated as a checked-out file (indicated by the red check glyph next to the file icon). Right-click MainWindow.xaml and select Check In….

17. In Team Explorer, type “Reverted to blue background” as the Comment and click Check In.

18. In the history view for MainWindow.xaml, click the Refresh button. This will update the list to reflect the most recent check in, which involved an edit and a rollback.

In document Introduction to Source Control --- (Page 28-36)

Related documents