git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Glen Choo <chooglen@google.com>
Cc: Carlo Arenas <carenas@gmail.com>,
	Aidan Gallagher <aidgal2@gmail.com>,
	git@vger.kernel.org
Subject: Re: Feature Request: `git commit --amend-to`
Date: Tue, 28 Sep 2021 21:54:28 +0200	[thread overview]
Message-ID: <87y27gv5bk.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <kl6l1r58r6ba.fsf@chooglen-macbookpro.roam.corp.google.com>


On Tue, Sep 28 2021, Glen Choo wrote:

> Carlo Arenas <carenas@gmail.com> writes:
>>   git commit --fixup reword:$SHA && EDITOR=true git rebase
>> --interactive --autosquash "$SHA^"
>>
>> granted it is not 1 command, but usually I find it useful to do
>> several of those and then one single
>> rebase at the end.
>
> This is fairly similar to what I use, though I use this through the
> Magit Emacs plugin.
>
> My concern with "--amend-to" is that the semantics aren't as simple as
> --amend.
>
> With --amend, you know you're working on the branch tip, so
> it's relatively simple to discard the last commit and create a new one.
>
> With something like --amend-to, you aren't just modifying a single
> commit, you are also introducing a potential merge conflict with every
> commit after that. You would have to provide some kind of facility for
> users to fix the merge conflicts. A command like git rebase --autosquash
> does a good job at communicating to users that they are actually doing a
> rebase and they need to be prepared to fix problems through a rebase UX.
> However, git commit --amend-to communicates none of that. A user who
> takes a cursory glance at git commit --amend-to has no idea that they
> are potentially comitting to a rebase.
>
> I personally think the current UI makes sense given how Git works. I
> also wish that it were easier to do --amend-to, but I think the problem
> has more to do with how Git manages merges and conflicts and less to do
> with having shortcuts in the CLI.

I think that users who'd like an --amend-to would probably be happy with
or might want to try out something like "hg absorb", which is something
I think we should have stolen in git already, but it's never too late.

I.e. it's a "git commit --squash" on steroids, which tries to find what
commit to amend things into.

See [1] (and [2] for an archive of the linked PDF) for a past
reference. There's a "git absorb" in Rust that I haven't tried out, but
seems interesting[3]. It looks like "absorb" is now part of "hg"
itself[4], but I'd looked at & tried it back when it was part of the
Facebook-specific patchset to "hg", which I understand has then mostly
or entirely gotten upstreamed in some way.

I'd think that for a git implementation we'd want to re-use the engine
we've got in range-diff.c, i.e. consider each unstaged hunk and find
which hunk/commit in say @{u}.. to squash it into.

1. https://lore.kernel.org/git/877ej0iuhc.fsf@evledraar.gmail.com
2. https://web.archive.org/web/20181003211051/http://files.lihdd.net/hgabsorb-note.pdf
3. https://crates.io/crates/git-absorb
4. https://gregoryszorc.com/blog/2018/11/05/absorbing-commit-changes-in-mercurial-4.8/

  reply	other threads:[~2021-09-28 20:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAENgTz2DoStQEqoKYKa-qMcyaez64u55mnv1HHOzDm392fuEqQ@mail.gmail.com>
2021-09-24 16:04 ` Feature Request: `git commit --amend-to` Aidan Gallagher
2021-09-24 17:15   ` Carlo Arenas
2021-09-28 16:52     ` Glen Choo
2021-09-28 19:54       ` Ævar Arnfjörð Bjarmason [this message]
2021-09-29 16:55         ` Glen Choo
2021-09-30  8:05           ` Fabian Stelzer
2021-09-30 13:56           ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y27gv5bk.fsf@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=aidgal2@gmail.com \
    --cc=carenas@gmail.com \
    --cc=chooglen@google.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).