git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] builtin/history: introduce "fixup" subcommand

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 23, 2026, 06:55 UTC
Message-ID
<aenCRKxak1l6GE3H@pks.im>
In-Reply-To
<CALnO6CCBA=OSvKT8D6-YR1S=x3VOa_MpzWfK6FJWPSXq0ysMPg@mail.gmail.com>
On Wed, Apr 22, 2026 at 03:06:12PM -0400, D. Ben Knoble wrote:
Show 23 quoted lines
> On Wed, Apr 22, 2026 at 6:30 AM Patrick Steinhardt <ps@pks.im> wrote:
> > diff --git a/Documentation/git-history.adoc b/Documentation/git-history.adoc
> > index 24dc907033..3cdfc8ba02 100644
> > --- a/Documentation/git-history.adoc
> > +++ b/Documentation/git-history.adoc
> > @@ -53,6 +55,19 @@ COMMANDS
> >
> >  The following commands are available to rewrite history in different ways:
> >
> > +`fixup <commit>`::
> > +       Apply the currently staged changes to the specified commit. The staged
> > +       changes are incorporated into the target commit's tree via a three-way
> > +       merge, using HEAD's tree as the merge base, which is equivalent to
> > +       linkgit:git-cherry-pick[1].
> 
> I'm not quite sure what, as a user of "git history fixup," I'm
> supposed to take from this. Does it make conflicts less likely when
> creating the new fixup? I imagine it doesn't help with conflicts
> between <commit> and HEAD that newly arise.
> 
> Anyway, I'd think the mechanics are less relevant than the end-user
> behavior at this point in the doc, unless the equivalence with
> cherry-pick is supposed to tell me something about that behavior.
There's at least two more or less obvious variants to do this:
  - You generate the diff between HEAD and index and then try to reapply
    the patch on top of the target commit.
  - You perform the three-way merge.

The second item is definitely more robust compared to generating the diff and reapplying it, and we use the exact same strategy to perform cherry-picks nowadays.

> > diff --git a/builtin/history.c b/builtin/history.c
> > index 549e352c74..6299f0dfa9 100644
> > --- a/builtin/history.c
> > +++ b/builtin/history.c
[snip]
Show 8 quoted lines
> > +       /*
> > +        * Perform the three-way merge to reapply changes in the index onto the
> > +        * target commit. This is using basically the same logic as a
> > +        * cherry-pick, where the base commit is our HEAD, ours is the original
> > +        * tree and theirs is the index tree.
> > +        */
> 
> OTOH, this explanation helps quite a bit here :)

Hm, okay. I felt that this explanation here is even more technical. How about:

    `fixup <commit>`::
        Apply the currently staged changes to the specified commit. This
        is done by performing a three-way merge between the HEAD commit,
        the target commit and the tree generated from staged changes.
        This is using the same logic as linkgit:git-cherry-pick[1].
Not sure that this is an improvement? Happy to hear other suggestions.
Thanks!
Patrick
Previous: D. Ben KnobleNext: D. Ben Knoble
Message 5 of 17 in “builtin/history: introduce "fixup" subcommand”
  1. 0/2 builtin/history: introduce "fixup" subcommandPatrick Steinhardt, Apr 22, 2026
  2. 1/2 builtin/history: generalize function to commit treesPatrick Steinhardt, Apr 22, 2026
  3. 2/2 builtin/history: introduce "fixup" subcommandPatrick Steinhardt, Apr 22, 2026
  4. D. Ben KnobleApr 22, 2026
  5. Patrick SteinhardtApr 23, 2026
  6. D. Ben KnobleApr 23, 2026
  7. Patrick SteinhardtApr 24, 2026
  8. D. Ben KnobleApr 24, 2026
  9. Tian YuchenApr 22, 2026
  10. Patrick SteinhardtApr 23, 2026
  11. 0/3 builtin/history: introduce "fixup" subcommandPatrick Steinhardt, Apr 27, 2026
  12. 1/3 replay: allow callers to control what happens with empty commitsPatrick Steinhardt, Apr 27, 2026
  13. Junio C HamanoMay 12, 2026
  14. 2/3 builtin/history: generalize function to commit treesPatrick Steinhardt, Apr 27, 2026
  15. 3/3 builtin/history: introduce "fixup" subcommandPatrick Steinhardt, Apr 27, 2026
  16. Junio C HamanoMay 12, 2026
  17. Patrick SteinhardtMay 12, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.