Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per line staging #59

Closed
non-descriptive opened this issue May 15, 2020 · 30 comments
Closed

Per line staging #59

non-descriptive opened this issue May 15, 2020 · 30 comments
Labels
enhancement New feature or request
Milestone

Comments

@non-descriptive
Copy link

Currently we can stage things only hunk by hunk or whole file at once. It would be nice to have ability to stage only current line or bunch of selected lines.

Flow would look like something like this:
We focus on diff panel and navigate to a hunk we want to work with.
Select lines we want to stage with arrows and some modifier key (is tui allow that kind of thing?) and press [S]tage button. If there were no selection stage current line.

Inspired by git-cola behavior, but it's a gui app.

@extrawurst
Copy link
Owner

Hi @non-descriptive thanks for your interest in gitui! I would love to have this feature. I need to checkout options how to make this ergonomic using keyboard only. will checkout how other tools are doing this and come up with a plan!

@extrawurst extrawurst added the enhancement New feature or request label May 15, 2020
@dufferzafar
Copy link

Lazygit does this via space. You can keep pressing space on changed lines and they'll get staged. (Same for unstage) It's pretty smooth.

@gilescope
Copy link

Hmm nice. In tig you can do '/' for break this hunk into two hunks but for some reason there are some hunks it refuses to split. Pressing space would work but being able to split a hunk at an arbitrary line would be great. Worst case you have to split twice to get at a specific line, but best case far less keystrokes (and tig compatibility).

@nbigaouette
Copy link

Using git add -p you can split a hunk but there is a limit to this split; this looks similar to what tig does.

I use gitup on macos (gui) and I always select exact lines with the mouse and press enter to stage. There does not seems to be a limit of split in gitup so it's probably a different mechanism behind the scene.

I would love to be able to select exact lines to stage!

@MuAlphaOmegaEpsilon
Copy link

This is one of the most important features for me regarding the use of a git client versus using git directly from the command line!

@jason0x43
Copy link

In tig you can stage an individual line from the unstaged diff by moving the cursor over it and hitting 1. You can unstage an individual line from the staged diff in the same way.

@nyanpasu64
Copy link

Sometimes I find it useful to edit a hunk-diff in a text editor. However, most GUI Git clients don't expose that option, only git add -p from the command line. Additionally it's tedious to replace leading - or + with a single space.

@hasufell
Copy link

In tig you can stage an individual line from the unstaged diff by moving the cursor over it and hitting 1. You can unstage an individual line from the staged diff in the same way.

I think 1 is a natural and easy to memorize key for this.

@teras
Copy link

teras commented Jun 19, 2020

I'd vote also for Space instead of "1", since "1" is already a keystroke to change "window".

@tuxlifan
Copy link

tuxlifan commented Aug 1, 2020

Any key to stage an individual line would be a huge improvement for me to finally be able to ditch "git gui" and stop mousing around 🥳

For vim users, Shift+v would be a familiar hotkey to start selecting lines.

Thank you for gitui! 😃

@alex-popov-tech
Copy link

super excited for this feature, that's probably the only thing which stopps me to switch to gitui from vim-fugitive :)

@stale
Copy link

stale bot commented Dec 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Dec 17, 2020
@hasufell
Copy link

Here is some activity.

@stale stale bot removed the wontfix This will not be worked on label Dec 17, 2020
@ser-drephs
Copy link
Contributor

It's already possible to select the lines using Shift+Arrow Down/Up on Windows. Would be nice if one could stage selected lines using Space.

@extrawurst
Copy link
Owner

@ser-drephs unfortunately its not trivial and did not bubble up high enough apparently for anyone who cares to go forward providing a PR :(

@extrawurst
Copy link
Owner

extrawurst commented Mar 7, 2021

ok work has begun on this! this will come in shape of actually four similar features:

  • discard unstaged modified lines
  • stage/unstage modified lines
  • discard untracked lines
  • stage/unstage untracked lines

I found an inspiration that supports this and is based on libgit2: nodegit - it seems surprisingly complicated - this is actually the only open source example that implements those per-line operations based on libgit2 and it has a few shortcomings that I am planning to lift: no support to stage/discard lines of untracked files and no line edits across multiple hunks

anyhow, stay tuned, discarding lines is on its way:
Screenflick Movie 104

@extrawurst extrawurst added this to the v0.13 milestone Mar 8, 2021
@extrawurst extrawurst mentioned this issue Mar 8, 2021
1 task
@extrawurst
Copy link
Owner

ok some progress: support for staging/unstaging changes in a tracked file:

Screenflick Movie 105

see #575

@non-descriptive
Copy link
Author

It's visible on the record that you press shift to select lines, but it looks like it doesn't really displayed in the actual UI. Is it possible to change "Scroll" caption when any of modifier keys pressed? If so, it might be a good idea to land an issue that depends on the current one.

@extrawurst
Copy link
Owner

It's visible on the record that you press shift to select lines, but it looks like it doesn't really displayed in the actual UI.

true the line selection is not yet represented in the command bar at the bottom

@extrawurst
Copy link
Owner

staging/unstaging in tracked files is merged. please give it a spin💪

Screenflick Movie 108

@extrawurst
Copy link
Owner

I consider this done now, the remaining two tasks (which I consider less important) will be tackled in a followup later: #582

@disrupted
Copy link

@extrawurst great addition! will you publish a new release with this feature?

@extrawurst
Copy link
Owner

@extrawurst great addition! will you publish a new release with this feature?

Yeah it’s scheduled for 0.13 and I am asking for more people to try it until then by building from master to make sure it’s as solid as possible

@nbigaouette
Copy link

Just tried it for say, 2 minutes, and it works well! I'll continue to use it tonight and tomorrow. I'll report if I find a problem.

Thanks a lot!!

@extrawurst extrawurst unpinned this issue Mar 11, 2021
@nbigaouette
Copy link

So I've used b5ef9b1 today. Works well! Good job :)

The only detail I can say, and that's a nitpick, is that when I stage a line, the "line cursor" (for a lack of better term...) moves to the top of the hunk. When the hunk is large and that a couple of lines are staged, it can be annoying to move the cursor back close to the original location.

Otherwise, thank you!!

@extrawurst
Copy link
Owner

The only detail I can say, and that's a nitpick, is that when I stage a line, the "line cursor" (for a lack of better term...) moves to the top of the hunk.

this is a very good point: #583

@extrawurst
Copy link
Owner

@nbigaouette i just merged this into master - would love to get your feedback on this! see #583

@nbigaouette
Copy link

Excellent! Just tried it and yes, cursor stays at proper location. Good job!!

Found another bug with the line staging. If I stage all lines of a hunk line by line, I end up with a hunk that has no diff but is still present in the diff window (it should disappear, like when you stage a whole hunk).

@extrawurst
Copy link
Owner

Excellent! Just tried it and yes, cursor stays at proper location. Good job!!

Found another bug with the line staging. If I stage all lines of a hunk line by line, I end up with a hunk that has no diff but is still present in the diff window (it should disappear, like when you stage a whole hunk).

Well that’s probably only a left-over whitespace change. Should be the same if u just insert a newline in some file. Such single newline changes are not well visualized yet. But that’s not a new issue

@nbigaouette
Copy link

True! Was only whitespaces.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests