git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Robin Dos Anjos <robin_1997@hotmail.fr>
To: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: General question about "git range-diff"
Date: Thu, 2 Nov 2023 18:56:39 +0000	[thread overview]
Message-ID: <PR3P195MB087847E68AD2032148EFCA039BA6A@PR3P195MB0878.EURP195.PROD.OUTLOOK.COM> (raw)

Hi git community!

I'm a bit intimidated as this is my first message in the mailing list but I'll give it a go!
First, I'd like to say that I've been using git for years and I think it's a fantastic tool. I always learn new things about it. It's so powerful and great.

Git 2.19 introduced one of my favorite features: "git range-diff". I use it all the time. Whenever I rebase a branch, I check that I resolved conflicts correctly using a range-diff. I avoided many bugs using this strategy.

But there is a caveat. Sometimes, the rebased branch contains numerous commits and resolving conflicts commit by commit is painful. This is particularly true of long-lived feature branches with multiple people pushing to it. In this situation, I usually squash all the commits during the rebase to resolve all conflicts at once.

The problem is that I'm no longer able to use "git range-diff" after such a rebase. On one side, I have N commits and on the other, I have a single commit which is the result of squashing N commits. "git range-diff" won't let me compare such histories because it wants to match commits one by one.

There are several workarounds to this situation.

The first one is to squash all the commits before rebasing. This works because I now have a single commit on both sides. I must say I don't really like this solution because it requires creating extra git objects needlessly.

Another one is to run "a diff of diffs" manually by running multiple git commands successively. This is the approach I have chosen and that I have been using for more than a year now. I basically dump the two diffs into two files on disk, then run "git diff --no-index" to compare those diffs and finally reimplement dual coloring by hand to display it in the terminal using less. This works surprisingly well and is usually very close to what "git range-diff" would itself output. I shared my NodeJS script which does exactly that on StackOverflow if you're interested in the details: https://stackoverflow.com/questions/70416396/how-to-pretty-format-an-arbitrary-diff-of-diffs

What I like about this is that, first, I don't pollute my repository with git objects that I will never use again, but more importantly, it's very versatile. I can specify the number of commits that I want on each side, and I will get my range-diff between my two arbitrary histories.

This is a quite different strategy from what "git range-diff" offers today. While matching the commits one by one is certainly useful in many contexts, I highly appreciate being able to opt out of that and switch to a patch-based range-diff when I need it.

This is so useful to me that I'm wondering why "git range-diff" does not implement this behavior. We could imagine a flag that would make it behave as I described. Is this something that was ever considered? Are there any technical difficulties that I'm completely missing? Do you think this could be helpful to other people?

I think it would be really nice to see this in git natively, hence my message. But if that is not feasible, I will still be happy to have my script!

Thank you for reading my lengthy message and I'm looking forward to reading your insights on the matter!

Best regards,

Robin DOS ANJOS

             reply	other threads:[~2023-11-02 18:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02 18:56 Robin Dos Anjos [this message]
2023-11-02 21:48 ` General question about "git range-diff" brian m. carlson
2023-11-02 23:21 ` Junio C Hamano
2023-11-03  1:25   ` Robin Dos Anjos

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=PR3P195MB087847E68AD2032148EFCA039BA6A@PR3P195MB0878.EURP195.PROD.OUTLOOK.COM \
    --to=robin_1997@hotmail.fr \
    --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).