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

Compare the changes between two versions of a file in your Git repo.

Team Services | TFS 2015 & 2017 | Visual Studio 2015 & 2017
  1. 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.

    View history in your repo for a file

  2. Find the latest commit for a branch by looking for its name on an arrow to the right of a commit.
  3. 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...
  4. The diff view shows lines removed from the older commit and added in the new one.

    View diff changes in Visual Studio

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

> git log index.html
commit bbc3b679197b659544a6f8070c79fb535b496613 Author: Francis Totten <ftottendev@outlook.com> Date: Thu Jun 30 13:42:50 2016 -0400 update landing page commit e5402fe710c25eca1b96a4e238eee9c01ed41c6a Author: Francis Totten <ftottendev@outlook.com> Date: Thu Jun 30 13:42:23 2016 -0400 initial commit

Filter the git log output based on author, description or date information by using the corresponding options. Leave out the filename if you want to see the commits matching all files in your repo.

> git log --author=frank@fabrikam.com index.html
> git log --since="2016-1-1"
> git log --before="2 weeks ago"
> git log --grep="css change"

View changes between two commits using git diff:

> git diff bbc3b67 e5402fe71 index.html

-    <link rel="stylesheet" href="app.cs"/>
+ <link rel="stylesheet" href="fabrikam.cs"/>

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.

View file versions 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.

View deleted files in your Git repo with Visual Studio

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.

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

Browse to your repo in Team Services or TFS. Select Branches from the menu under Code:

Open the branches view in Team Services/TFS

Locate your branch and select the ... icon to view the branch options. Select Compare branches.

Select the ellipses icon to open branch options, then select team services

Select the branch to compare to from the drop-downs at the top. The view will display all changes between the branches.

Use git diff to compare the contents of two branches. You can compare any combination of local and remote branches. The output shows the deletions and additions between the two versions of the code.
> git diff users/frank/feature origin/master
index 36843b8..03afc4b 100644
--- a/tsapp/index.html
+++ b/tsapp/index.html
@@ -4,7 +4,7 @@
 <head>
     <meta charset="utf-8" />
     <title>TypeScript HTML App</title>
-    <link rel="stylesheet" href="fabrikam-test.css" type="text/css" />
+ <link rel="stylesheet" href="fabrikam.css" type="text/css" /> <script src="app.js"></script> </head> ... --- a/tsapp/app.ts +++ b/tsapp/app.ts constructor(element: HTMLElement) { this.element = element; - this.element.innerHTML += "The time is: ";
+ this.element.innerHTML += "The time is now: "; this.span = document.createElement('span'); this.element.appendChild(this.span); this.span.innerText = new Date().toUTCString();
This will output the diff for every change between the branches. You can narrow down specific file changes by specifying a file after the branch names:
> git diff users/frank/feature origin/master index.html