lazyjj icon indicating copy to clipboard operation
lazyjj copied to clipboard

Split support

Open Cretezy opened this issue 1 year ago • 1 comments

Would be great to split ~~and squash~~.

~~Squash:~~

  • ~~When squashing on @, squash to parent~~
  • ~~When squashing on other change, squash working copy to it~~
  • Allow interactive squashing with scm-record

Squashing has been added.


Split:

  • Splits whatever copy is selected
  • Allow interactive squashing with scm-record

Cretezy avatar May 27 '24 07:05 Cretezy

Just a note about splitting, which would be lovely to have. Below is a brief description of how lazygit's very workable interactive staging UI works; it's best in breed and worth considering for any interactive staging tool. Hopefully, this comment helps inform a future interactive split UI.

lazygit presents a two pane, side by side diff with the workspace diff on the left and the staged diff on the right. One pane has focus at a time, and <Tab> toggles focus to the other. The user selects one or more lines in the focused pane and hits <Space> to push them to the other side, thus staging or unstaging them. To select what lines to push, there are three modes, number 3 is the game changer:

  1. Line at a time: arrows to select a line
  2. Visual mode: select a set of lines (v to enter, arrows move an end of the selection; 'o' changes ends)
  3. "minihunk"[1] mode: All contiguous changed lines are selected ('a' to enter, arrows navigate to next/prev minihunk).

In all modes, d reverts the selected change lines (with confirmation) from both the workspace and the stage (handy for removing debug lines) and e opens the file in your $EDITOR so you can tweak it (handy for indentation and alignment fixes).

The main drawback is that its diff engine sometimes intermingles new and deleted lines in ways that make it impossible to stage correct code by only moving change lines. This seems to happen most often when the change contains a brace—sometimes the diff engine fixates on a moved brace, making it a single line of context and splitting up added and removed lines around it in such a way as to prevent staging correct code.

[1] lazygit 0.53 includes PR 4684, which tweaked 3 above from working on full diff hunks to minihunks. A "minihunk" (my name, not its) is a group of contiguous change lines; each separated by context; a traditional diff hunk is one or more "minihunks", including their context.

barries avatar Jul 20 '25 11:07 barries