View and manage past versions in Git

You can get detailed information about the every change to your codebase, and, if necessary, modify past changes.

  • View historical data in Visual Studio You can get historical data about both your published and unpublished branches as you develop your code in Visual Studio.

    • File history

    • Annotated file history

    • Branch history

    • Commit details

  • View historical data in your web browser You can get the same historical data that’s available in Visual Studio about your published branches from the web portal. You can also communicate with your team about past changes.

    • File history

    • Annotated file history

    • Branch history

    • Commit details

  • Modify past changes Developing software is an iterative process, so sometimes you need to:

    • Amend the latest commit on your dev machine

    • Revert a commit

  • Q & A

View historical data in Visual Studio

You can view the history of a file or a branch, and from there view the details about any commit in the history.

File history

You can view the history of a file from solution explorer (Keyboard: Ctrl + Alt, L).

Git file history from Solution Explorer

If you need more information about a commit, you can view commit details.

Annotated file history

You can view historical changes within a file (annotate). (You must have installed Visual Studio 2013 Update 2 or a subsequent version to use this feature.)

Changes annotated in a file

When you move your cursor into a block affected by a commit, all other instances of that commit are highlighted in the left pane of the window.

Branch history

In Visual Studio, you can view the history of both unpublished branches and published branches.

Go to the commits page (Keyboard: Ctrl + 0, O) and then fetch the latest changes from your team project.

Fetch link on Commits page

View the history.

History from the Changes page

  1. These commits are the history of the message branch.

  2. Someone applied the tag flat to the commit with the message add message.

  3. The master branch references a commit that is in the history of the message branch, so it appears in the history of the message branch.

  4. If you need more information, you can view details about a commit.

Commit details

You can view details about a commit, including what was changed in each file affected by the commit.

Commit details

If this commit has been published, you can view it in your web browser from the Actions menu and then communicate with your team about it.

If you want to modify the message, you can, as long as this commit is the latest commit on your dev machine and it has not been pushed to a shared repository. Just make your changes and choose Amend Message. You can also amend the content of the latest commit if it hasn’t been pushed. commit. See Modify changes that exist only on your dev machine (amend).

View historical data in your web browser

From your team project’s web portal, you can view the past commits in a published branch. You can also write comments and send messages about your commits.

Open your team project’s web portal (Keyboard: Ctrl + 0, A) from the home page.

On the Home page, choose Web Access

File history

You can view the history of a file from your team project’s web portal.

File history on web portal

Annotated file history

You can also view historical changes within a file (annotate).

Annotated changes to a file on web portal

Branch history

You can see the history of a branch in your web browser. For example, Raisa published the hotfix branch so that Jamal can test her changes. Jamal views the history of this branch on the commits page.

Branch history on web portal

Commit details

You can view details about a commit, including what was changed in each file affected by the commit.

Git commit details on the web portal

From the details page you can comment on a commit and send email about it.

If you want to add a comment, move your pointer over the line you want to comment about, then choose the comment icon.

Commit page, diff - insert message icon.

Enter your comment.

Commit page, diff - comment on line of code

You can see from the commits page that a comment has been made on the commit.

Commits page - message icon on a commit

Modify past changes

Developing software is an iterative process, so sometimes you might need to:

  • Amend the latest commit on your dev machine

  • Revert a commit

You must have installed Visual Studio 2013 Update 2 or a subsequent version to use these features.

Amend the latest commit on your dev machine

Did you just commit a change that is slightly wrong, or forget to include changes you made to another file? To amend the latest commit on your dev machine:

  1. Make sure you have saved any changes you want to include in the amended commit.

  2. On the Changes page (Keyboard: Ctrl + 0, G), make sure the changes you want to include are listed in Included Changes. You can also modify the message.

  3. Open the Actions menu and choose Amend Previous Commit.

Your previous commit is de-referenced and a new commit is created.

You can also amend the message of the latest commit from the Commit Details page, described earlier.

Note

You should not amend a commit that has been pushed to a shared repository, such as one in your TFS team project. In most cases, Visual Studio blocks you from doing this when a commit has been pushed to a team project. Under some circumstances, however, you might not be blocked from amending the commit. For example, you will not be blocked from amending a commit if your remote repository is hosted by another service such as CodePlex or GitHub). If you amend a pushed commit, you might have to resolve conflicts when you pull from the remote repository.

Revert a commit

Do you need to roll back a change because, for example, it caused a bug? Here’s now to revert the changes in a commit:

  1. Initiate the revert:

    • Right-click the commit in the History window and choose Revert.

    • Choose the Revert link on the Commit Details page.

  2. Choose Yes if you are sure you want to revert the commit.

    Note

    If a conflict appears, you can resolve it, or if you are not ready to do that, you can choose Undo Revert.

  3. A “Revert” commit is added to the Outgoing Commits list on the Unsynced Commits page (Keyboard Ctrl + 0, O).

Q & A

Q: I was blocked by the system because I don’t have permission. How do I get it?

A: Permission reference for Team Foundation Server

Q: What is the difference between the author and the committer?

A: In most cases, the author and the committer of a commit are the same person. One situation in which they differ is a commit that has been rebased. For example, if Julia rebases a commit from Peter, she becomes the committer of that commit, but Peter is still the author of the commit.

Q: How do I restructure (rebase) my local commits?

A:Work from the Git command prompt

Q: What is a branch? How do I use them?

A: In Git, all work you do is in a branch. If you have never explicitly created a branch, you are probably working in the default branch, which is typically called master. You can use branches to switch contexts, suspend work, and isolate risk.

Q: What are tags? How do I use them?

A: A tag is essentially a pointer to a specific commit. You can use tags to label a certain point in time in your codebase. Many teams use tags to point to a release point. You can apply tags from the command prompt. See Work from the Git command prompt

Q: Can I view history from other places?

A: You can also view history from the home page (Keyboard: Ctrl + 0, H), the commits page (Keyboard: Ctrl + 0, O), and the branches page (Keyboard: Ctrl + 0, N).

Q: Can I create a branch from a specific commit or tag?

A: Yes. You can do this from the command prompt using the <start-point> option. See Git-scm: git-branch(1) Manual Page