| title | Review your repo history |
|---|---|
| titleSuffix | Azure Repos |
| description | Learn how to review Git history to find out when files changed, who changed them, and what changes were made. |
| ms.assetid | aed4bd97-378a-45f6-8b13-59143fccfe3b |
| ms.service | azure-devops-repos |
| ms.topic | how-to |
| monikerRange | <= azure-devops |
| ms.date | 10/18/2022 |
| ms.subservice | azure-devops-repos-git |
[!INCLUDE version-lt-eq-azure-devops] [!INCLUDE version-vs-gt-eq-2019]
Git uses commit metadata like parent links, author details, and timestamps to track the history of changes in a repo. You can review the Git history to find out when files changed, who changed them, and what changes were made.
When people create and merge feature branches into a target branch using pull requests, the development history of the target branch might not be a straight chronological line. So, when you review the history of changes to a file on the target branch, keep in mind that the order of commits is influenced by merge strategy and merge date, not just the original date of the changes. For example, the most recent commit on the main branch may introduce a change that was made weeks ago in a feature branch that was only just merged into the main branch using a three-way merge.
To learn how to use Visual Studio 2022 with Git, see How Visual Studio makes version control easy with Git.
[!INCLUDE azure-repos-prerequisites]
When you want to figure out how and when a particular file change occurred, you might need to compare different versions of the same file from different commits, possibly in different branches.
The Azure DevOps team project site lets you compare two versions of the same file from commits in the same branch, but doesn't support comparing file versions across branches.
-
From your web browser, open the team project for your Azure DevOps organization. In the Repo > Files view, select a file and choose the Compare tab.
:::image type="content" source="media/review-history/browser/file-version-compare.png" border="true" alt-text="Screenshot of the File Compare view on the Azure DevOps project page." lightbox="media/review-history/browser/file-version-compare-lrg.png":::
-
In the Compare tab, choose the two commits that contain the file versions you want to compare. The diff view shows any new, deleted, or modified file lines.
:::image type="content" source="media/review-history/browser/select-commits-for-compare.png" border="true" alt-text="Screenshot of the Compare options in the File Compare view on the Azure DevOps repo page.":::
Note
GitHub lets you compare two versions of the same file from different commits across different branches. To compare, append /compare/<commit1>..<commit2> to your GitHub repo URL to navigate to the comparison page. The comparison page contains a diff view of each file that differs. For more information on commit comparison in GitHub, see Comparing commits.
Visual Studio 2022 provides a Git version control experience by using the Git menu, Git Changes, and through context menus in Solution Explorer. Visual Studio 2019 version 16.8 also offers the Team Explorer Git user interface. For more information, see the Visual Studio 2019 - Team Explorer tab.
[!INCLUDE Compare file versions]
Visual Studio 2019 provides a Git version control experience by using the Git menu, Git Changes, and through context menus in Solution Explorer.
[!INCLUDE Compare file versions]
Team Explorer doesn't provide support for this feature.
The git diff command can compare different versions of the same file from different commits across different branches. The git log command can help you identify the commits that contain the file versions you want to compare.
-
Use
git logand specify a file to list the commits that changed the file:git log <file>By default, the command output starts with the most recent commit in the current branch, and then iterates backward through ancestor commits (regardless of branch) by following the parent links in each commit's metadata.
Here's an example of output for the command
git log index.html:commit bbc3b679197b659544a6f8070c79fb535b496613 Date: Thu Jun 30 13:42:50 2021 -0400 update landing page commit e5402fe710c25eca1b96a4e238eee9c01ed41c6a Date: Thu Jun 30 13:42:23 2021 -0400 initial commit -
Use
git diffand specify a file and two commits to see how the committed file versions differ:git diff <commit1> <commit2> <file>Here's an example of output for the command
git diff bbc3b67 e5402fe index.html:- <link rel="stylesheet" href="app.cs"/> + <link rel="stylesheet" href="fabrikam.cs"/>The output shows that one line was deleted and one line was added.
To limit] the commits that git log lists, you can filter by author, date, message, changed content, and more. For example:
-
git log --author=frank@fabrikam.com index.htmlonly lists commits by the specified author. -
git log --since="2022-5-1"only lists commits created after the specified date. -
git log --before="yesterday"only lists commits created before the specified relative date. -
git log --grep="css change"only lists commits with the specified text in their message. -
git log -S"myVariable"only lists commits that introduce or remove the specified string. -
git log -G"myVar.*"only lists commits that introduce or remove the specified regex string. -
git log -3only lists the last three commits.
You have several format options for the commit list. For example:
-
git log --abbrev-commitlists commits using an abbreviated ID (SHA-1 checksum). -
git log --onelinelists each commit in a single-line abbreviated format. -
git log --patch index.htmllists each commit together with a diff of the changes.
You can restore a specific version of a file from Git history, even if the file was edited, deleted, or renamed in a later commit. Restoring an older version of a file doesn't create a new commit with the change. To update your branch with the restored file version, you'll need to commit the change.
The Azure DevOps team project site lets you revert all changes made by a specific commit, but doesn't support reverting changes to a specific file within the commit.
[!INCLUDE Compare file versions]
[!INCLUDE Compare file versions]
Visual Studio 2019 version 16.8 and later versions provides a Git version control experience while maintaining the Team Explorer Git user interface. To use Team Explorer, uncheck Tools > Options > Preview Features > New Git user experience from the menu bar.
-
In Solution Explorer, select a file and choose Git > View History from the file's context menu to open a Git History tab for the selected file.
:::image type="content" source="media/review-history/visual-studio-2019/common/view-file-history-option.png" border="true" alt-text="Screenshot of the View History option in the file context menu in Solution Explorer in Visual Studio 2019." lightbox="media/review-history/visual-studio-2019/common/view-file-history-option-lrg.png":::
-
In the Git History tab, select a commit and choose View Commit Details from the commit's context menu to open the Commit Details view.
:::image type="content" source="media/review-history/visual-studio-2019/common/view-commit-details-option.png" border="true" alt-text="Screenshot of the View Commit Details option in the commit context menu in the commit History view in Visual Studio 2019." lightbox="media/review-history/visual-studio-2019/common/view-commit-details-option-lrg.png":::
-
In the Commit Details view, select the file and choose Open from the file's context menu to open the previous version of the file in a new tab.
:::image type="content" source="media/review-history/visual-studio-2019/team-explorer/open-file-option.png" border="true" alt-text="Screenshot of the Open option in the file context menu in the Commit Details view of Team Explorer in Visual Studio 2019." lightbox="media/review-history/visual-studio-2019/team-explorer/open-file-option-lrg.png":::
-
Choose File > Save As from the menu bar to save the restored version of the file.
You can use the git checkout or git show commands to restore a specific version of a file from Git history.
-
git checkout reverts a file to a previously committed version if you specify the file and a commit:
git checkout <commit> <file>For example,
git checkout 85435fac src/app.tswill revert thesrc/app.tsfile to its version in commit85435fac. -
git show prints the contents of a previously committed file version, which you can redirect to an output file:
git show <commit>:<file> > <output file>For example,
git show 85435fac:src/app.ts > /archive/oldapp.tswill write the contents ofapp.tsin commit85435facto/archive/oldapp.ts.
Tip
To find the ID a previous commit, see Compare file versions or Find a commit ID.
You can compare any local or remote branches to review the changes that will result from a merge or rebase. Branch comparison lets you check for merge conflicts and see how changes by others might affect your work.
Visual Studio 2019 and earlier versions don't support branch comparison, so if you're using one of those versions you can compare branches on the Git command line or using your web browser—if your repo is hosted in Azure Repos or GitHub. Visual Studio 2022 supports branch comparison, as described in Compare branches.
-
From your web browser, open the team project for your Azure DevOps organization. In the Repos > Branches view, select the ellipsis for any branch and choose Compare branches to open the Branch compare view.
:::image type="content" source="media/review-history/browser/branch-context-menu.png" border="true" alt-text="Screenshot of the branch context menu in the Branches view on the Azure DevOps project page." lightbox="media/review-history/browser/branch-context-menu-lrg.png":::
-
In the Branch compare view, choose the two branches that you want to compare. Select the Files tab for a diff view of the new, deleted, or modified lines in each changed file.
:::image type="content" source="media/review-history/browser/branch-compare.png" border="true" alt-text="Screenshot of the Files tab in the Branch Compare view on the Azure DevOps repo page." lightbox="media/review-history/browser/branch-compare-lrg.png":::
Note
GitHub supports branch comparison. To compare two branches, append /compare/<branch1>...<branch2> to your GitHub repo URL to navigate to the comparison page. The comparison page contains a diff view of each file that differs. For more information on branch comparison in GitHub, see Comparing branches.
To compare a branch with the current branch, right-click a branch in the Branches pane of your repository, and then select the compare option. The context menu specifies the names of the current and the target branches:
:::image type="content" source="media/review-history/visual-studio-2022/branch-context-menu-inline.png" border="true" alt-text="Screenshot of the branch context menu in the Branches area of Visual Studio 2022." lightbox="media/review-history/visual-studio-2022/branch-context-menu-expanded.png":::
Visual Studio 2019 doesn't support branch comparison. However, you can compare branches on the Git command line or using your web browser—if your repo is hosted in Azure Repos or GitHub.
Tip
You can access the web portal from the Team Explorer Home view by choosing Web Portal.
:::image type="content" source="media/review-history/visual-studio-2019/team-explorer/web-portal-link.png" border="true" alt-text="Screenshot showing the Web Portal link in the Home view of Team Explorer in Visual Studio 2019.":::
Visual Studio 2019 doesn't support branch comparison. However, you can compare branches on the Git command line or using your web browser—if your repo is hosted in Azure Repos or GitHub.
Tip
You can access the web portal from the Team Explorer Home view by choosing Web Portal.
:::image type="content" source="media/review-history/visual-studio-2019/team-explorer/web-portal-link.png" border="true" alt-text="Screenshot showing the Web Portal link in the Home view of Team Explorer in Visual Studio 2019.":::
To compare any two local or remote branches, you can use the Git diff command specifying the branch names:
git diff <branch1> <branch2>Git compares the commit at the tip of one branch with the commit at the tip of the other. The diff output will show the deletions and additions between each file in the two branches.
Here's an example of output for the command git diff users/frank/feature origin/main, which compares a local branch with a remote branch:
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();
To narrow down comparison to a specific file, specify the file in the diff command:
git diff <branch1> <branch2> <file>For example, git diff users/frank/feature origin/main index.html will only generate a diff for the index.html file.
[!div class="nextstepaction"] Understand Git history