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

Re: [PATCH] range-diff: add --matched-only to skip one-sided commits

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 11, 2026, 17:19 UTC
Message-ID
<xmqqik4bbt9c.fsf@gitster.g>
In-Reply-To
<pull.2401.git.git.1789144877632.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 24 quoted lines
> diff --git a/Documentation/git-range-diff.adoc b/Documentation/git-range-diff.adoc
> index 5cc5e2ed56..58e59e8e3b 100644
> --- a/Documentation/git-range-diff.adoc
> +++ b/Documentation/git-range-diff.adoc
> @@ -10,7 +10,8 @@ SYNOPSIS
>  [synopsis]
>  git range-diff [--color=[<when>]] [--no-color] [<diff-options>]
>  	[--no-dual-color] [--creation-factor=<factor>]
> -	[--left-only | --right-only] [--diff-merges=<format>]
> +	[--left-only | --right-only | --matched-only]
> +	[--diff-merges=<format>]
>  	[--remerge-diff] [--no-notes | --notes[=<ref>]]
>  	( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
>  	[[--] <path>...]
> @@ -82,6 +83,13 @@ to revert to color all lines according to the outer diff markers
>  	Suppress commits that are missing from the second specified range
>  	(or the "right range" when using the `<rev1>...<rev2>` form).
>  
> +`--matched-only`::
> +	Only emit commits that have a corresponding commit in the other
> +	range, suppressing any commit that exists on only one side. This is
> +	the same as using `--left-only` and `--right-only` together. Useful
> +	to skip added or removed commits when reviewing how the commits
> +	that survived a rebase changed.

While conceptually it is the same as giving "--hide-right-only" (which would have hidden the right-only entry) and "--hide-left-only" at the same time, because the existing two options are not defined in terms of "hiding" entries that have only one side (which would have logically allowed combining) but instead showing "only" one side (which makes it impossible to give them together, and indeed that is the first thing range-diff.c:show_range_diff() checks and yields an error), this description is not accurate.

I wonder if the implementation actually can be more like
 - give "--hide-left-only" and "--hide-right-only" as synonyms to
   "--right-only" and "--left-only", and deprecate the original;
 - allow them to be given together, which will give the new
   behaviour you are introducing, i.e., skip steps without both
   sides from the output;
 - give a short-hand synonym, "--matched-only", to truly behave the
   same as giving "--hide-{left,right}-only" together.

which would allow the above explanation to be more accurate? I dunno.

> +	if (range_diff_opts->left_only + range_diff_opts->right_only +
> +	    range_diff_opts->matched_only > 1)
> +		res = error(_("options '%s', '%s', or '%s' cannot be used together"),
> +			    "--left-only", "--right-only", "--matched-only");
Don't we have die_for_incompatible_opt3() to do this?

The basic idea sounds good. The unmatched entries do serve as a strong hint that a greater --creation-factor may help. For example,

Show 7 quoted lines
> +		git range-diff -s --abbrev=7 combined-old...combined-new >actual &&
> +		cat >expect <<-EOF &&
> +		1:  $old_only_oid < -:  ------- c-old-only
> +		-:  ------- > 1:  $new_only_oid c-new-only
> +		2:  $common_old_oid = 2:  $common_new_oid c-common
> +		EOF
> +		test_cmp expect actual &&

the above clearly shows that the command might compare c-old-only and c-new-only with a better creation factor settings.

But because the entries are numbered, gaps in the numbers, like this output

> +		git range-diff -s --abbrev=7 --matched-only combined-old...combined-new \
> +			>actual &&
> +		echo "2:  $common_old_oid = 2:  $common_new_oid c-common" >expect &&
> +		test_cmp expect actual

may be sufficient (we can tell that 1 was omitted), except that somehow we at least need to be aware that there were only 2 commits on both sides (it may be hiding commits 3 thru 99 as unmatching pairs and we lose that hint from the new output), which is not a huge downside.

Thanks.
Previous: Harald Nordgren via GitGitGadgetNext: Harald Nordgren
Message 2 of 23 in “range-diff: add --matched-only to skip one-sided commits”
  1. range-diff: add --matched-only to skip one-sided commitsHarald Nordgren via GitGitGadget, Sep 11, 2026
  2. Junio C HamanoSep 11, 2026
  3. Harald NordgrenSep 11, 2026
  4. Junio C HamanoSep 11, 2026
  5. Harald NordgrenSep 11, 2026
  6. Junio C HamanoSep 11, 2026
  7. range-diff: add --matched-only to skip one-sided commitsHarald Nordgren via GitGitGadget, Sep 11, 2026
  8. Junio C HamanoSep 14, 2026
  9. range-diff: add --matched-only to skip one-sided commitsHarald Nordgren via GitGitGadget, Sep 15, 2026
  10. Junio C HamanoNov 2, 2026
  11. Harald NordgrenNov 2, 2026
  12. Ben KnobleNov 2, 2026
  13. Harald NordgrenNov 2, 2026
  14. Harald NordgrenNov 2, 2026
  15. Matt HunterNov 3, 2026
  16. Junio C HamanoNov 3, 2026
  17. Ben KnobleNov 3, 2026
  18. Matt HunterNov 3, 2026
  19. Junio C HamanoNov 3, 2026
  20. Kristoffer HaugsbakkNov 4, 2026
  21. Ben KnobleNov 4, 2026
  22. Kristoffer HaugsbakkNov 4, 2026
  23. Junio C HamanoNov 2, 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.