संपादित करें

इसके माध्यम से साझा किया गया


Review history

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

Visual Studio 2019 | Visual Studio 2022

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.

In this article you learn how to:

  • Compare file versions
  • Restore files
  • Compare branches

To learn how to use Visual Studio 2022 with Git, see How Visual Studio makes version control easy with Git.

Compare file versions

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.

  1. 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.

    Screenshot of the File Compare view on the Azure DevOps project page.

  2. 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.

    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.

Restore files

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.

Compare branches

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.

  1. 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.

    Screenshot of the branch context menu in the Branches view on the Azure DevOps project page.

  2. 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.

    Screenshot of the Files tab in the Branch Compare view on the Azure DevOps repo page.

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.

Next steps