Web lists-archives.com

Re: Bug: `git commit --fixup` with duplicate commit messages




On Fri, Dec 14, 2018 at 12:30:28PM +0000, Oliver Joseph Ash wrote:
> I believe I have found a bug in `git commit --fixup`.

That's not a bug, it's actually the documented behaviour of rebase
--autosquash.

As you figured out, the squash/fixup is based on whether the message
has the squash!/fixup! prefix and the subject matches. But it also
allows specifying hashes.

So for fixups, you can be explicit and use: git commit -m 'fixup! SHA'.

Similarly for squashes. (But a little less friendly as you'll need to
deal with passing an argument to -m that contains newlines).

But adding 'squash! SHA' when the editor opens should also work.

I believe the main reason this works based on subject message matching
is to be more friendly with scenarios where you're sharing series of
commits that include fixups and squashes. (Either via format patch, or
by rebasing the series on a newer base without --autosquash).

On such cases the commit you're trying to fixup will have a different
OID, so any hardcoded OID will be useless while commit message matching
works most of the time.

One potential improvement to this is to teach --fixup and --squash to
also add trailers like: "{fixup,squash}: SHA" or "target: SHA" and teach
--autosquash to respect it when possible.

Thoughts?