Re: Git Evolve
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Oct 2, 2018, 23:09 UTC
- Message-ID
- <20181002230948.GB18063@syl>
- In-Reply-To
- <877ej0iuhc.fsf@evledraar.gmail.com>
On Tue, Oct 02, 2018 at 11:11:11AM +0200, Ævar Arnfjörð Bjarmason wrote:
You timed this email quite well ;-).
Show 45 quoted lines
> On Tue, Oct 02 2018, Taylor Blau wrote:
>
> > Hi Stefan,
> >
> > On Sat, Sep 29, 2018 at 04:00:04PM -0700, Stefan Xenos wrote:
> >> Hello, List!
> >>
> >> I'm interested in porting something like Mercurial's evolve command to
> >> Git.
> >
> > Welcome to Git :-). I think that the discussion in this thread is good,
> > but it's not why I'm replying. I have also wanted a Mercurial feature in
> > Git, but a different one than yours.
> >
> > Specifically, I've wanted the 'hg absorb' command. My understanding of
> > the commands functionality is that it builds a sort of flamegraph-esque
> > view of the blame, and then cascades downwards parts of a change. I am
> > sure that I'm not doing the command justice, so I'll defer to [1] where
> > it is explained in more detail.
> >
> > The benefit of this command is that it gives you a way to--without
> > ambiguity--absorb changes into earlier commits, and in fact, the
> > earliest commit that they make sense to belong to.
> >
> > This would simplify my workflow greatly when re-rolling patches, as I
> > often want to rewrite a part of an earlier commit. This is certainly
> > possible by a number of different `git rebase` invocations (e.g., (1)
> > create fixup commits, and then re-order them, or (2) mark points in your
> > history as 'edit', and rewrite them in a detached state, and I'm sure
> > many more).
> >
> > I'm curious if you or anyone else has thought about how this might work
> > in Git.
>
> I've wanted a "git absorb" for a while, but have done no actual work on
> it, I just found out about it.
>
> I think a combination of these two heuristics would probably do the
> trick:
>
> 1. If a change in your "git diff" output has a hunk whose lines overlap
> with an earlier commit in the @{u}.. range, we do the equivalent of
> "git add -p", select that hunk, and "git commit --fixup <that
> commit>". We fixup the most recent commit that matches (otherwise
> commit>we'd conflict).I had imagined this working slightly differently. I think about it in terms of a flamegraph-shape, where each line is affected by gravity. Consider this:
[---------------] L0 L1 L2 L3 L4 L5 L6 L7
Here's a line in a diff that affects L1-L4. Were we to create a ``fixup'' to L3-L4, it would look like this:
[-----] --|
[---------|-----] <-|
L0 L1 L2 L3 L4 L5 L6 L7The commit owning the adjacent edit hunk is the one that gets the changes applied to it.
Consider instead the case where we have two overlapping parts of a change:
[-----|----]
[---------|-----]
L0 L1 L2 L3 L4 L5 L6 L7The left-hand side of the top-most hunk belongs to the hunk below it, but the right-hand side is ``affected by gravity'' down to the base:
[-----|
[---------|-----]|---]
L0 L1 L2 L3 L4 L5 L6 L7And thus could be reapplied anywhere. I have not spent time proving this, but I believe that this resolves appropriate bases without ambiguity (or, at least can detect when finding a base introduces ambiguity).
Show 11 quoted lines
> 2. Have some mode where we fall back from #1 and consider changes to > entire files, if that's unambiguous. > > The neat thing about this would be that you could tweak how promiscuous > #1 would be via the -U option to git-diff, and #2 would just be a > special case of -U9999999999999 (we should really add a -Uinf...). > > Then once you ran this you could run "git rebase -i --autosquash" to see > how the TODO list would look, and optionally have some "git absorb > --now" or whatever to do the "git add -p", "git commit --fixup" and "git > rebase --autosquash" all in one go.
That's cool. I hadn't known about '--autosquash' before, but it now makes sense to me why I have often seen patches that begin with "fixup!".
Another thought that I am reminded of was an off-list discussion with Peff, where we thought that a particularly Git-like way to implement something like this would be to generate a set of commits that would be immediately '--autosquash'-able.
> > [1]: http://files.lihdd.net/hgabsorb-note.pdf
Thanks, Taylor