How to view the Git History in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
4 min

banner

# Table of Contents

  1. How to view the Git History in Visual Studio Code
  2. View the Git history in VS Code using the GitLens extension
  3. View the Git history in VS Code using the Git History

# How to view the Git History in Visual Studio Code

To view the Git history in VS Code:

  1. Select a file in Explorer.
  2. Click on the TIMELINE tab at the bottom of the sidebar to expand it.

click on timeline tab

  1. Click on the filter icon and select Git History.

click filter icon select git history

  1. View the git history of the file directly in your editor.

Selecting a specific commit opens a diff view of the changes introduced by the given commit.

Here is a short click that demonstrates how to use the TIMELINE view.

view git history in timeline tab

You can right-click on an entry to:

  • Open the changes
  • Select for Compare
  • Copy the commit ID
  • Copy the commit message

right click on entry

The Timeline view automatically shows the timeline for the currently selected file.

The built-in Git extension contributes a timeline that shows the Git commit history of the given file.

By default, the view is collapsed in Explorer (the left sidebar), so you have to click on it to expand it.

Alternatively, you can:

  1. Open a file.

  2. Press:

  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type timeline and select Explorer: Focus on Timeline View.

select focus in timeline view

# View the Git history in VS Code using the GitLens extension

If you need a more complete way to view the Git history in VS Code, install the GitLens extension.

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux.
    • Command + Shift + X on macOS.
  1. Type GitLens.

install gitlens extension

  1. Click on the Install button.

Make sure to install the correct GitLens extension as shown in the screenshot.

You can click on the Source Control icon in the Activity Bar on the left to view the commits and the file history using the GitLens extension.

view commits and file history using gitlens

If you click on a specific file a git diff between this and the previous commit is shown.

You can also press:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type GitLens history and select one of the commands.

gitlens history commands

You can right-click on a file in Explorer and select Open File History.

right click open file history

You can also right-click on a folder in Explorer and select Open Folder History.

right click open folder history

# View the Git history in VS Code using the Git History

You can also use the Git History extension to view the Git history in VS Code.

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux.
    • Command + Shift + X on macOS.
  1. Type Git History.

install git history extension

  1. Click on the Install button.

Make sure to install the correct Git History extension as shown in the screenshot.

The extension can be used to:

  • View and search Git log along with the graph and details.
  • View a previous copy of a file.
  • View and search the history
  • Compare branches, commits and files across commits

Once the extension is installed:

  1. Open a specific file.
  2. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type git history and select one of the commands.

select one of git history commands

For example, you can select the Git: View History (git log) command to view the commit history for each branch for all or specific authors and look at the graph.

git view history log

The Git: View File History command displays the commit history for the selected file.

The Git: Line history command displays the commit history for the selected line or code block.

Once you open a file, you can also click on the Git: View File History icon to view the file's commit history.

click view file history icon

Clicking on the icon opens a new Window that shows the file's git history.

show file git history

I've also written an article on how to undo the last Git commit in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.