Git - Visual Studio 2022, v17.3.0, Line Staging


With VS2022, v17.3.0 we have gotten a new Git feature: line staging. We will give an overview and compare it with SourceTree, which already has that feature.


The problem we are facing is how to stage (prepare for commit) only a part of the file that was changed, not the whole file. The new version of VS2022, v 17.3.0, introduces a new feature that enables us to do exactly that.

1.1 Testing methodology

We will use a small piece of code, and add two lines of code. Let us assume that we want to stage and commit the first line, but not the second one, in the next commit.

Line Staging in VS2022

When we added two lines, VS2022 immediately marked file changes and showed the file in the changes (Work-files) directory.

In order to get to the option to do “Line staging” and stage only the first line, we need to get to “compare mode."

In compare mode, we right-click the line that we want to stage and select the option.

We can see that file is listed two times, in both the “Staged changed” control and in the “Changes” control. Selecting the file will give us a diff of what is staged.

You are now ready to commit if you like.

Line Staging in SourceTree

In the integrated editor in SourceTree, you can select the line you want to stage. Above that you will see buttons that enable you to do that.

Once you select that line and stage it, you will see the same file in both controls, “Staged files” and “Unstaged files." Clicking on the file will show you the file content, from the perspective of Git.

You are now ready to commit if you like.


In this article, we showed what the new feature of VS2022, v 17.3.0, “Line staging” looks like. We also showed that other Git Gui clients, like SourceTree, already have that feature.

Similar Articles