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

Re: git diff without intermediate commits

From
Jeff King <peff@peff.net>
Date
Mar 9, 2023, 06:22 UTC
Message-ID
<ZAl7JI3FZdUgrvkq@coredump.intra.peff.net>
In-Reply-To
<MN2PR15MB3454AE2CE41E79F2B260DDD3E1B59@MN2PR15MB3454.namprd15.prod.outlook.com>
On Thu, Mar 09, 2023 at 05:52:15AM +0000, Sudheer D wrote:
> Is there a feature readily available in git that will compare just
> commit1 & commit2 without considering the intermediate merge commits?

No. A diff is comparing two endpoints, without regards to the history. You can choose different endpoints, but I don't think that really helps your case (sometimes using the merge base as the preimage, which you can access via the three-dot "diff commit1...commit2" can help, but I don't think it does in your case).

> If the answer to the above question to is 'no', if I am providing a
> patch for the same for 'git diff' & 'git difftool' probably with a new
> command line option, would you accept it?

We'd never say "yes" to accepting a patch without seeing it. I'm not inherently against such a feature, but I have trouble seeing how it could even be implemented. You are really asking for a diff between the state of "commit2" and "commit1 as if it had been applied on top of those merges". But there is no guarantee that commit1 can be applied there. If the merges touch some of the same lines, it won't work (and likewise, if you try to do clever things like subtracting out bits of the diff that come from the intermediate merges, it won't always work).

You can try something like:
  # use a detached HEAD for looking around; we go
  # the parent of commit2 here, which should be merge_commit_n
  git checkout --detach $commit2^
  # this may fail if commit1 conflicts with any of the merges
  git cherry-pick $commit1
  # but now we can see just the differences from commit1->commit2
  git diff HEAD $commit2

which will work sometimes, but I don't think it would be a good idea to build a feature around it.

-Peff
Previous: Sudheer DNext: Junio C Hamano
Message 2 of 3 in “git diff without intermediate commits”
  1. Sudheer DMar 9, 2023
  2. Jeff KingMar 9, 2023
  3. Junio C HamanoMar 9, 2023

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.