VSTS | TFS 2018 | TFS 2017 | TFS 2015 | VS 2017 | VS 2015
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.
In this tutorial you learn how to:
- Compare files
- Retrieve files
- Compare branches
Compare the changes between two versions of a file in your Git repo.
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.
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 an 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.
To retrieve a previous version of a file that exists in your Visual Studio project:
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.
To retrieve a previous version of a file that was deleted in a previous commit:
Open the Changes view in Team Explorer and 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.
The retrieved version of a file is not automatically saved to your project. To save the retrieved version to your project, select 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.
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.
Comparing branches can be done in the web portal, which you can access from the Team Explorer Home view in Visual Studio by choosing Web Portal.
Select Branches from the menu under Code. Locate your branch and select the ... icon to view the branch options. Select Compare branches.
Select the branch to compare to from the drop-downs at the top. The view will display all changes between the branches.