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

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

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

We are giving an overview and comments on a new feature of VS2022, v17.3.0, Git Line staging

Abstract: With VS2022, v17.3.0 we are getting a new Git feature: Line staging. We are giving an overview and comparing it with SourceTree which already has that feature.

1 Introduction

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 2 lines of code. Let us assume we want to stage and commit the first line, but not the second one in the next commit.

2 Line Staging in VS2022

When we added 2 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 just “right-click” the line we want to stage and select the option.

Then we can see that file is listed 2 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.

3 Line Staging in SourceTree

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

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

You are now ready to commit if you like.

4 Conclusion

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.

No Comments

Sorry, the comment form is closed at this time.