microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.39k stars 29.32k forks source link

Git: Support line staging #9475

Open isidorn opened 8 years ago

isidorn commented 8 years ago

From @kachkaev I can't find out how to select just two deleted lines out of 5 going sequentially and stage only the ones I want. Any time I select something and click that menu item, the whole block gets staged. The same happens when unstaging.

isidorn commented 8 years ago

Unfortunetly this can not be supported with the current ux design. Namely, a diff editor does not support selecting deleted lines thus it is impossible for the user to specify which deleted lines to stage. Closing as will not fix.

kachkaev commented 8 years ago

Why is the issue closed? Should not it stay open until the UX design is changed? Staging line-by-line is a pretty basic and pretty demanded feature, which I've seen in all git GUIs I've used.

isidorn commented 8 years ago

Sure, we can reopen this and keep it as a feature request to be able to stage deleted lines one by one. PRs are welcome

Dominik-K commented 6 years ago

@isidorn @joaomoreno Why is it designed to disable right hand side staging?

Selecting the deleted lines in the right hand side would solve this issue. Would this be easy to code?

Ilyes512 commented 5 years ago

Any update on this? Can't believe that this is not supported?

epouthier commented 4 years ago

I add shortcut to stage/unstage selected lines in files (Ctrl+G Ctrl+S) GitExtensions use S to stage, R to revert, U to unstage. On VSCode the shortcut can replace selected lines if we are clumsy.

Can you improve support stage selected lines ?

MPLew-is commented 2 years ago

This is the last thing stopping me from being able to use VS Code's fully-integrated source control functionality - doing something simple like only staging the deletion of a line for a specific commit even if the diff thinks another line is its replacement is currently impossible, and has me using git gui for most of my committing at this point.

Are there any updates as to if this is planned, or any pointers on what would need to be done to get this feature working?

EmilStenstrom commented 2 years ago

This is the only thing missing for me to go all in on VS Code for Git instead of my old Git GUI.

AgustinRamiroDiaz commented 2 years ago

There's this option to do it: https://www.youtube.com/watch?v=sYTwr1OSUlo

You need to select the lines, hit F1 and run "Git: Stage Selected Ranges"

EmilStenstrom commented 2 years ago

@AgustinRamiroDiaz In the current UI, it's not possible to select changes where there were only deleted lines. Since it's not possible to select them, it's not possible to issue commands on them. In the video you link, there are changes that are only addition, and changes that are additions and deletions. No changes with only deletions.

AgustinRamiroDiaz commented 2 years ago

@EmilStenstrom You can select only deleted lines by selecting before and after where the lines would be. One thing that I wasn't able to do though was to select line by line from the deleted block

I've made a quick demo: https://www.loom.com/share/86ab3fb5f3e24c3c9d3fc2651e8d7c72

EmilStenstrom commented 2 years ago

You are right: Selecting deleted lines that are surrounded by untouched code works. But selecting individual lines is not possible, and you can't add a deleted line if you've also added lines before or after that you don't want to include.

The only UI that makes sense here is being able to pick lines (deleted or not) you want to add.

mikkorantalainen commented 2 years ago

I cannot believe that "git gui" is still the state-of-art GUI even today when I want to commit logical lines instead of files. Hopefully this gets fixed. I'd be very happy with literally simple reimplementation of git gui interface. If I could get syntax highlighting to work while selecting lines to add or remove, I'd be very happy!

EmilStenstrom commented 2 years ago

Just for reference, this is what this looks like in Tower, a Mac client for Git:

image

You click in the margin to select a line, and clicking Stage Lines at the top right stages only those line. You can click either deleted or added lines.

MetRonnie commented 1 year ago

For reference (taken from https://github.com/desktop/desktop/issues/1688#issuecomment-306638427):

GitHub Desktop screen capture

pilgunboris commented 1 year ago

The absence of this ability in vscode is the only reason I have to use an extra git GUI tool to rewrite commits history before opening something for code review. I hope this can be implemented soon.

ADTC commented 1 year ago

If I right-click the deleted line, I get a small context menu with options like the following: (I also get this context menu by clicking the little bulb icon on the left, although this is currently blocked by regression #197743.)

It would be a start to add "Stage deleted line (number)" or "Unstage deleted line (number)" here (depending on context).

Also, if I consecutively right-click two lines within the same deleted diff block, the context menu could have an additional option to work on that range between the two lines (inclusive): "Stage deleted lines (first line number-last line number)" (or "Unstage ...").

Once this simple menu option is added and released, fancier UI can be explored in a later release for the easier staging of multiple lines.

davibe commented 6 months ago

Contrary to what was stated above, I am able to select one or more deleted lines using the split view (by disabling the inline diff view). In that situation, trying to stage the selected 'range' does nothing. Similarly I can select the added lines alone, but then staging them also stages the removed ones within the same git hunk.

This is a bug, not a ux design limitation or choice.

zachpoblete commented 3 months ago

@davibe Yep, that bug is literally the most upvoted papercut; see #8226.

zachpoblete commented 3 months ago

If anyone's wondering, #204221 mentioned this issue by mistake (which is why the PR description is edited).

karahanyilmazer commented 3 weeks ago

I am also interested in this feature as I find myself staging and deleting individual lines quite often. "Stage selected ranges" doesn't do the trick for me all the time. I would very much appreciate having this functionality in my workflow.