Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a feeling this question might be so dumb that someone will say something like 'Yeah, there's a big orange button on the right', but is it possible to stage and commit individual code lines into Git from inside Visual Studio?

I currently use SourceTree as my main interface for Git, which is an excellent piece of software, and it does indeed allow individual lines to be staged and committed. I do quite like the file-difference viewer in Visual Studio, however, and would like to stage a commit from this screen if this is possible.

Any advice or pointers to good information on using Git from within Visual Studio (I've already read quite a few) would be very much appreciated.

Kind wishes ~ Patrick

What I have tried:

I've tried having a good dig through the Visual Studio menus and also read a few tutorials and guides on using Git inside Visual Studio.
Posted
Updated 13-Mar-18 0:16am
Comments
Richard Deeming 13-Mar-18 10:29am    
You can apparently do it in VSCode: Are partial git commits possible in VSCode?[^]

But it looks like you can't do it in Visual Studio.
Richard Deeming 13-Mar-18 10:31am    
Here's a UserVoice request to add the feature:
Add "Stage Selected Lines" feature to Visual Studio git client[^]
Patrick Skelton 13-Mar-18 10:57am    
Thanks for the replies, Richard. Looks like the VS team are missing a trick from Code team. Hope they do it soon because they do have a very nice difference viewer.

1 solution

All source control software works on files, not lines (internally they will extract the lines that have changed and store them).

You can commit single files if you need to.

So the solution for you is to commit as soon as possible (the least code changes that you are comfortable with).

Personally I use TortoiseGit to commit outside VS.
 
Share this answer
 
Comments
Patrick Skelton 13-Mar-18 6:25am    
SourceTree undoubtedly does do some 'magic' behind the scenes, but from the user's point-of-view it allows individual lines of code to be committed, skipped or changed back to the previous version. It is so useful, I now struggle to remember how I ever got by without it. I hoped Visual Studio might allow something similar.
Mehdi Gholam 13-Mar-18 6:28am    
It probably creates a "virtual file" of your selected changes and commits that.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900