How to highlight modified lines in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
3 min

banner

# How to highlight modified lines in Visual Studio Code

To highlight the modified lines in Visual Studio Code:

  1. Initialize a git repository with the git init command.
shell
git init

initialize git repository

If you need to open VS Code in the current directory, use the following command.

shell
code .
  1. Make changes to a specific file.

  2. You can stage and commit the changes with the following commands.

shell
git add . git commit -m 'your commit message'
  1. If you make changes again to the files you track with version control, the modified lines will be highlighted.

highlight-modified-lines-in-vscode

In order to highlight the modified lines in VS Code, you have to use version control (Git).

Notice that there are left borders with multiple different colors depending on the modification.

  • A blue bar to the left means that the lines have been modified. In other words, you previously staged and committed the code and have since made modifications.
  • A green bar to the left means that the lines have been added. In other words, the last time you committed your changes, these lines were not in the file.
  • The red triangle to the left is placed where lines have been deleted.

highlight-modified-lines-in-vscode

You can view the exact changes that were made to the file by:

  1. Clicking on Source Control in the left sidebar.

  2. Selecting the specific file.

click on source control and select file

You can also focus the Source Control view with a keyboard shortcut:

  • Ctrl + Shift + G (works on Windows, macOS and Linux).

Once you select the file a side-by-side view opens where you can view the changes you've made to the file since the last commit.

# Unstage your changes if you don't see the modified lines

Note that if you stage the file, the highlighting of the modified lines disappears.

You can either stage a file with git add . or by clicking on the + icon next to the file's name in the Source Control pane on the left.

Here is a short clip that demonstrates how this works.

stage and unstage file to see highlighted changes

You can also stage and unstage files using the terminal.

shell
git add . git status git restore --staged .

git stage and unstage using terminal

Note that if the file is staged, you won't see the highlighting of the modified lines.

If you still aren't able to see the modified lines after unstaging your files, try to restart VS Code.

I've also written a detailed guide on the meaning of the U and M file markers in the left sidebar in VS Code when working with Git.

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