threads / discuss / 62474

Feature Request: Interactively pick fixup revision

Subject: Feature Request: Interactively pick fixup revision

## tl;dr

12 messages between Nov 9, 2024 and Nov 16, 2024.

replies: 11people: 6as markdown or json

Martin Imre· Nov 9, 2024, 11:41 UTC · lore
Hi,
first email to this list, so please forgive me if I'm doing something wrong.

My usual workflow is using `git commit --fixup <revision>` quite frequently, as it eases the code reviewing process and allows for a clean history later on.

One thing that is always cumbersome is to first find the SHA of the revision that I plan to commit a fixup to. I usually use git log and then copy the revision. I even wrote a script that eases this process using fzf: ``` #!/bin/bash

res=$(git log --oneline | fzf) ref=$(echo $res | cut -d ' ' -f1)

git commit --fixup ${ref} ```

I don't think fzf is really necessary here, but it speeds things up.

Anyhow, I'm really surprised that this isn't a feature of git. I could see a `git commit --fixup` (without a revision) or `git commit --fixup --interactive` open up the git log and let one pick the revision they want to commit a fixup to.

Cheers, Martin

rsbecker@nexbridge.com· Nov 9, 2024, 13:09 UTC · re: Martin Imre · lore

RE: Feature Request: Interactively pick fixup revision

On November 9, 2024 6:41 AM, Martin Imre wrote:
Show 24 quoted lines
>first email to this list, so please forgive me if I'm doing something wrong.
>
>My usual workflow is using `git commit --fixup <revision>` quite frequently, as it
>eases the code reviewing process and allows for a clean history later on.
>
>One thing that is always cumbersome is to first find the SHA of the revision that I
>plan to commit a fixup to.
>I usually use git log and then copy the revision.
>I even wrote a script that eases this process using fzf:
>```
>#!/bin/bash
>
>res=$(git log --oneline | fzf)
>ref=$(echo $res | cut -d ' ' -f1)
>
>git commit --fixup ${ref}
>```
>
>I don't think fzf is really necessary here, but it speeds things up.
>
>Anyhow, I'm really surprised that this isn't a feature of git.
>I could see a `git commit --fixup` (without a revision) or `git commit --fixup --
>interactive` open up the git log and let one pick the revision they want to commit a
>fixup to.

You might find that git rebase --autosquash -i <commit> might do what you are looking for. This allows you to clean up your topic branch prior to creating a pull request. Loads of documentation online about its use.

Good luck, Randall

Martin Imre· Nov 9, 2024, 13:39 UTC · re: rsbecker@nexbridge.com · lore

Re: Feature Request: Interactively pick fixup revision

On Sat, Nov 9, 2context for all your replies. Please also see below.024 at 2:09 PM <rsbecker@nexbridge.com> wrote:

Show 34 quoted lines
>
> On November 9, 2024 6:41 AM, Martin Imre wrote:
> >first email to this list, so please forgive me if I'm doing something wrong.
> >
> >My usual workflow is using `git commit --fixup <revision>` quite frequently, as it
> >eases the code reviewing process and allows for a clean history later on.
> >
> >One thing that is always cumbersome is to first find the SHA of the revision that I
> >plan to commit a fixup to.
> >I usually use git log and then copy the revision.
> >I even wrote a script that eases this process using fzf:
> >```
> >#!/bin/bash
> >
> >res=$(git log --oneline | fzf)
> >ref=$(echo $res | cut -d ' ' -f1)
> >
> >git commit --fixup ${ref}
> >```
> >
> >I don't think fzf is really necessary here, but it speeds things up.
> >
> >Anyhow, I'm really surprised that this isn't a feature of git.
> >I could see a `git commit --fixup` (without a revision) or `git commit --fixup --
> >interactive` open up the git log and let one pick the revision they want to commit a
> >fixup to.
>
> You might find that git rebase --autosquash -i <commit> might do what
> you are looking for. This allows you to clean up your topic branch prior
> to creating a pull request. Loads of documentation online about its use.
>
> Good luck,
> Randall
>
I think you might have misunderstood what I'm trying to achieve.

After adding a fixup commit, I'm anyway running `git rebase --autosquash -i <commit>`.

However, my request is to get an interactive way to pick _which_ commit a fixup is targeting. Ie, I'm trying to run something that pops up a pager with the commit log for me to pick a commit that is then passed to `git commit --fixup <commit>`.

If you have fzf, try running my script in a git repo with some changes and you'll see what I'm trying to achieve.

Cheers, Martin

Matěj Cepl· Nov 9, 2024, 14:55 UTC · re: Martin Imre · lore

Re: Feature Request: Interactively pick fixup revision

On Sat Nov 9, 2024 at 12:41 PM CET, Martin Imre wrote:
> My usual workflow is using `git commit --fixup <revision>` quite
> frequently, as it eases the code reviewing process and allows for a
> clean history later on.
https://github.com/keis/git-fixup/

but at least as a minimal improvement, I would limit list of commits to those which are touched in the staging area:

  ref=$(git log --oneline -- $(git diff --cached|lsdiff --strip 1)|fzf|cut -d ' ' -f1)
(lsdiff is from patchutils)
Best,
Matěj
-- 
http://matej.ceplovi.cz/blog/, @mcepl@floss.social
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
Ty zlý dávaj’ ty hodný pryč. // Those evil ones put away those good ones.
  -- Magda Ceplová
Kristoffer Haugsbakk· Nov 9, 2024, 17:13 UTC · re: Matěj Cepl · lore

Re: Feature Request: Interactively pick fixup revision

On Sat, Nov 9, 2024, at 15:55, Matěj Cepl wrote:
Show 14 quoted lines
> On Sat Nov 9, 2024 at 12:41 PM CET, Martin Imre wrote:
>> My usual workflow is using `git commit --fixup <revision>` quite
>> frequently, as it eases the code reviewing process and allows for a
>> clean history later on.
>
> https://github.com/keis/git-fixup/
>
> but at least as a minimal improvement, I would limit list of
> commits to those which are touched in the staging area:
>
>   ref=$(git log --oneline -- $(git diff --cached|lsdiff --strip
> 1)|fzf|cut -d ' ' -f1)
>
> (lsdiff is from patchutils)

This or git-absorb(1) (I have only tried the latter) is good if you want to fixup previously touched lines. That is likely to be the case for a fixup command. But maybe you for example want to add a test to some change which is in a different file. In which case you want to pick the commit manually.

I haven’t heard of lsdiff(1) though. That’s something I have been wanting lately. Thanks.

-- 
Kristoffer Haugsbakk
Matěj Cepl· Nov 9, 2024, 19:43 UTC · re: Kristoffer Haugsbakk · lore

Re: Feature Request: Interactively pick fixup revision

On Sat Nov 9, 2024 at 6:13 PM CET, Kristoffer Haugsbakk wrote:
> I haven’t heard of lsdiff(1) though.  That’s something I have been
> wanting lately.  Thanks.

https://github.com/twaugh/patchutils (part of any Linux distro) … it is absolutely indispensable set of tools for any developer, IMHO.

Matěj
-- 
http://matej.ceplovi.cz/blog/, @mcepl@floss.social
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
The state is the great fictitious entity by which everyone seeks
to live at the expense of everyone else.
      -- Frederick Bastiat
Martin Imre· Nov 10, 2024, 07:55 UTC · re: Matěj Cepl · lore

Re: Feature Request: Interactively pick fixup revision

Thanks for pointing me towards https://github.com/keis/git-fixup/ and git-absorb (https://github.com/tummychow/git-absorb). I'll try them out and see if I like the ergonomics of them.

Just as a general question: With 2 (or even more) different implementations that solve the same problem, wouldn't this be a good addition for a future version of git?

Also, out of curiosity, how do they achieve their binaries to be called as git commands, ie, why can I call the binary `git-fixup` via `git fixup`?

Cheers, Martin

Kristoffer Haugsbakk· Nov 10, 2024, 07:59 UTC · re: Martin Imre · lore

Re: Feature Request: Interactively pick fixup revision

On Sun, Nov 10, 2024, at 08:55, Martin Imre wrote:
> Also, out of curiosity, how do they achieve their binaries to be
> called as git commands, ie, why can I call the binary `git-fixup` via
> `git fixup`?

They don’t do anything special. Any script or binary that you define yourself will be treated the same. `git` takes care of it.

Stefan Haller· Nov 10, 2024, 16:09 UTC · re: Martin Imre · lore

Re: Feature Request: Interactively pick fixup revision

On 10.11.24 08:55, Martin Imre wrote:
Show 7 quoted lines
> Thanks for pointing me towards https://github.com/keis/git-fixup/ and
> git-absorb (https://github.com/tummychow/git-absorb).
> I'll try them out and see if I like the ergonomics of them.
> 
> Just as a general question: With 2 (or even more) different
> implementations that solve the same problem, wouldn't this be a good
> addition for a future version of git?

I'll throw a third one into the mix: lazygit. It's a TUI client that has similar functionality built in. (See [1])

As for why this isn't built in: there are a lot of subtleties to how exactly it works, and people might not agree on these. For example, git-absorb seems to have certain design goals that I don't agree with; I have written a longish document about that if you're interested. [2]

[1] <https://github.com/jesseduffield/lazygit/blob/master/
     docs/Fixup_Commits.md#finding-the-commit-to-create-a-fixup-for>
[2] <https://github.com/jesseduffield/lazygit/blob/master/docs/
     dev/Find_Base_Commit_For_Fixup_Design.md>
Matěj Cepl· Nov 11, 2024, 02:53 UTC · re: Martin Imre · lore

Re: Feature Request: Interactively pick fixup revision

On Sun Nov 10, 2024 at 8:55 AM CET, Martin Imre wrote:
> Just as a general question: With 2 (or even more) different
> implementations that solve the same problem, wouldn’t this be a good
> addition for a future version of git?

There are few problems, one which is the implementation language: git-absorb is Rust and git-fixup is bash (using arrays and other non-POSIX constructs).

Documentation/howto/new-command.txt declares:
    Most subcommands are written in C or shell.  A few are written in
    Perl.
    (And Python scripts are allowed for some specific tasks, namely GUI)

Shell script here quite emphatically means POSIX shell (or at least not using widely non-POSIX constructs like arrays), not bash. In order to even be able to consider any of these commands to be submitted to git proper, it would have to be ported first.

Best,
Matěj
-- 
http://matej.ceplovi.cz/blog/, @mcepl@floss.social
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
Never ascribe to malice that which is adequately explained by
stupidity.
    -- Napoleon Bonaparte (or many other people to whom this
       quote is ascribed)
Oswald Buddenhagen· Nov 16, 2024, 17:39 UTC · re: Matěj Cepl · lore

Re: Feature Request: Interactively pick fixup revision

On Mon, 11 Nov 2024 03:53:47 +0100, Matěj Cepl wrote:
Show 9 quoted lines
> On Sun Nov 10, 2024 at 8:55 AM CET, Martin Imre wrote:
> > Just as a general question: With 2 (or even more) different
> > implementations that solve the same problem, wouldn’t this be a good
> > addition for a future version of git?
>
> There are few problems, one which is the implementation language:
> git-absorb is Rust and git-fixup is bash (using arrays and other
> non-POSIX constructs).
>

fwiw, i just stumbled over https://github.com/torbiak/git-autofixup which is written in perl. no idea how good it is compared to git-absorb.

Kristoffer Haugsbakk· Nov 9, 2024, 17:08 UTC · re: Martin Imre · lore

Re: Feature Request: Interactively pick fixup revision

On Sat, Nov 9, 2024, at 12:41, Martin Imre wrote:
Show 30 quoted lines
> Hi,
>
> first email to this list, so please forgive me if I'm doing something wrong.
>
> My usual workflow is using `git commit --fixup <revision>` quite
> frequently, as it eases the code reviewing process and allows for a
> clean history later on.
>
> One thing that is always cumbersome is to first find the SHA of the
> revision that I plan to commit a fixup to.
> I usually use git log and then copy the revision.
> I even wrote a script that eases this process using fzf:
> ```
> #!/bin/bash
>
> res=$(git log --oneline | fzf)
> ref=$(echo $res | cut -d ' ' -f1)
>
> git commit --fixup ${ref}
> ```
>
> I don't think fzf is really necessary here, but it speeds things up.
>
> Anyhow, I'm really surprised that this isn't a feature of git.
> I could see a `git commit --fixup` (without a revision) or `git commit
> --fixup --interactive` open up the git log and let one pick the
> revision they want to commit a fixup to.
>
> Cheers,
> Martin

This could be useful for a lot of commands. I use git-notes(1) a lot (just as a niche example). I often wanna just get a list of the last commits (e.g. `@{u}..`) when I want to edit a note. (I should try to use fzf for that, thanks by the way!)

I’m imagining that some RFC implementation of this could get replies like “but why just for `git commit --fixup/--squash…`?”

As far as third-party programs are concerned: see this section of the Lazygit readme:[1]

> Pressing shift+a on any commit will amend that commit with the
> currently staged changes (running an interactive rebase in the
> background).

Not the exact same thing of course. You don’t get intermediary fixup commit since it just runs interactive rebase in the background (so it runs an uninteractive rebase…).

I haven’t tried Lazygit myself.
🔗 1: https://github.com/jesseduffield/lazygit

← back to recent threads