Click here to Skip to main content
15,886,519 members
Articles / DevOps / Git
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
11 Aug 2022CPOL2 min read 5.3K   7   2
An overview and comments on a new feature of VS2022, v17.3.0, Git Line staging
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 two lines of code. Let us assume we want to stage and commit the first line, but not the second one in the next commit.

Image 1

2. Line Staging in VS2022

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

Image 2

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

Image 3

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

Image 4

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

Image 5

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.

Image 6

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.

Image 7

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.

5. History

  • 12th August, 2022: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Serbia Serbia
Mark Pelf is the pen name of just another Software Engineer from Belgrade, Serbia.
My Blog https://markpelf.com/

Comments and Discussions

 
QuestionVery useful Pin
S.H.Bouwhuis15-Sep-22 0:22
S.H.Bouwhuis15-Sep-22 0:22 
QuestionSuggestion Pin
Graeme_Grant12-Aug-22 1:46
mvaGraeme_Grant12-Aug-22 1:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.