Review history

Last Update: 1/23/2017

Team Services | TFS 2015 & TFS 2017 | Visual Studio 2015 & 2017

Overview

Git uses the parent reference information stored in each commit to manage a full history of your development.
Review this commit history to find out when file changes were made and determine differences between versions of your code.

Git's use of feature branches and merges through pull requests mean that the commit history of your development doesn't form a straight, chronological line.
When you use history to compare versions, think in terms of file changes between two commits instead of file changes between two points in time.
A recent change to a file in the master branch may have come from a commit created two weeks ago in a feature branch but was only merged yesterday.

Compare files

Team Services | TFS 2015 & 2017 | Visual Studio 2015 & 2017

Right-click the file in Solution Explorer and choose View History.... The history window will appear showing the commit ID, author, date, and description of all changes to the file in your local repo across all branches.

Find the latest commit for a branch by looking for its name on an arrow to the right of a commit.

View changes from the previous version of the file by right-clicking and choosing Compare with previous.... View the changes between any two versions by selecting both commits, then right-clicking and select Compare...

The diff view shows lines removed from the older commit and added in the new one.

Use the git log command to view the commits that changed a file in your repo for your current branch.

Retrieve files

Retrieve a specific version of a file from your history, even if the file was deleted or renamed in the latest version of your code.
Retrieving a older version of the file doesn't make any changes to your current branch. Create a new commit to bring the older version of the file into
your branch.

Team Services | TFS 2015 & 2017 | Visual Studio 2015 & 2017

Right-click the file in Solution Explorer and select View History. The Visual Studio History view will appear, showing the commits in your repo that updated the file.
You can filter the commits to find the exact commit with the file version you want to restore. Double click on the version to open it in Visual Studio.

Retrieve deleted files in your repo by opening the Changes view in Team Explorer. Select View History from the Actions drop-down. Right-click the commit
containing the version of the file you want to restore and select View Commit Details.

Right click the file to restore in the Commit Details in Team Explorer and select Open.

Save the version to your project by selecting Save As... from the File menu. If you save the file in your current project, either as a new file or overwriting
an existing one, you'll need to commit your changes to add the previous version to your local branch.

Use git log to find the version to restore and git checkout or git show to restore the file from your history.

Find the commit with the version of the file you need to restore using git log using the steps from comparing versions above.
Restore the version in its current location using git checkout:

> git checkout 85435fac src/app.ts

Using git checkout this way will rewrite the current verison of the file at that path location.

Restore a file to any location by using git show. This command prints the file contents to the terminal-you'll want to redirect the output to your desired location.

> git show 85435fac:src/app.ts > /home/frank/oldapp.ts

Compare branches

Review potential changes from a merge or rebase by comparing branches directly.
You can compare both local and remote branches, which is useful when checking for potential merge conflicts or to see how the
changes others have made will affect your work.