git-log--graph icon indicating copy to clipboard operation
git-log--graph copied to clipboard

git squash multiple selected commits

Open phil294 opened this issue 1 year ago • 9 comments

would be nice to have for some but I don't know how the respective git command(s) for that would look like.

Squashing is possible with git of course, but since the multiple-commits-selection can have arbitrary gaps...

image

I don't know what the action should do here (git / basic bash commands) without rewriting the entire extension

phil294 avatar Feb 22 '24 21:02 phil294

Suggestion:

  • Do not allow multiple selections (more than two) with Ctrl+click
  • Allow selection of multiple commits (without gaps) with Shift+click - with that selection it's maybe easier to squash them

hansu avatar Feb 24 '24 08:02 hansu

Do not allow multiple selections (more than two) with Ctrl+click

but it's really handy for cherry-picking and reverting them :/

Allow selection of multiple commits (without gaps) with Shift+click

that's already possible, but yeah, with gaps allowed

phil294 avatar Feb 24 '24 11:02 phil294

Do not allow multiple selections (more than two) with Ctrl+click

but it's really handy for cherry-picking and reverting them :/

Do you usually revert multiple commits at once?

Allow selection of multiple commits (without gaps) with Shift+click

that's already possible, but yeah, with gaps allowed

No, shift + click doesn't work with v0.1.14 on my machine...

hansu avatar Feb 25 '24 10:02 hansu

No, shift + click doesn't work with v0.1.14 on my machine...

are you using MacOS?

phil294 avatar Feb 25 '24 17:02 phil294

No, shift + click doesn't work with v0.1.14 on my machine...

are you using MacOS?

No, Linux

hansu avatar Feb 25 '24 18:02 hansu

As an initial iteration, could the squash action only appear when the selection has no gaps? That would be sufficiently useful for many (perhaps most) cases.

SeijiSuenaga avatar Mar 15 '24 08:03 SeijiSuenaga

No, shift + click doesn't work with v0.1.14 on my machine...

@hansu is this still the case in the latest release?

As an initial iteration, could the squash action only appear when the selection has no gaps? That would be sufficiently useful for many (perhaps most) cases.

@SeijiSuenaga yes but main problem with this approach is that the concept of "gap" isn't distinct, as the ordering of commits depends on the sorting options currently set, and other branches' commits could be in the way. There's related discussion about this in #110. The continuitation logic would have to rely on Git's internal commit parent logic, but when it conflicts with the UI, that can be rather confusing. Shouldn't stop us from implementing this feature still.

phil294 avatar Nov 29 '24 21:11 phil294

No, shift + click doesn't work with v0.1.14 on my machine...

@hansu is this still the case in the latest release?

Works now, thanks!

Edit: But only when selecting from top to bottom - the other way around not.

hansu avatar Nov 30 '24 11:11 hansu

Leaving aside the UI problem above, a non-interactive squash can be achieved using git reset --soft [commit id of parent of oldest commit to squash] && git commit. That can be done. But it would also be preferable to be able to squash older commits, not up to the current one. For that, only a scripted interactive rebase can be used, probably similar to the current "edit message" action: git commit --allow-empty --only -m "squash! [hash1]\nsquash! [hash2]" && git -c sequence.editor=: rebase -i --autosquash "[hash1]^" (not tested, just pseudo command). I'm not sure if doing it like this for the last n commits has any downsides compared to the first solution though.

Another challenge will be pre-filling the commit message field with the combination of the selected commits.

phil294 avatar Apr 13 '25 11:04 phil294