{"thread":{"id":"59365","subject":"git diff without intermediate commits","startedAt":"2023-03-09T05:52:21Z","lastAt":"2023-03-09T17:16:24Z","messageCount":3,"participants":["Sudheer D","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"473253","messageId":"MN2PR15MB3454AE2CE41E79F2B260DDD3E1B59@MN2PR15MB3454.namprd15.prod.outlook.com","threadId":"59365","inReplyTo":null,"subject":"git diff without intermediate commits","fromName":"Sudheer D","fromEmail":"sudheer.d@ibm.com","sentAt":"2023-03-09T05:52:15Z","receivedAt":"2023-03-09T05:52:21Z","isPatch":false,"sender":{"key":"sudheer.d@ibm.com","avatar":null},"body":"Hello List,\n\nI have a question regarding git diff command.\n\nMy Problem:\nWhen we work in git projects under github, we will normally\ncreate a local branch, make some changes commit it\ncreate a PR & send that for review\nmay have to merge 'master' branch one or more times to make sure that automated build works properly after merging the latest master branch.\nWill enhance the PR based on review comments OR add new changes.\n\nAssuming that my commit history is as follows:\n\na. commit1     <-- My local commit 1\nb. merge_commit1 <- Merge commit from 'master'\nc. merge_commit2\n....\nf. merge_commit_n\ng. commit2  <-- My local commit 2\n\n\n\nNow, if I issue 'git diff commit1 commit2', git will show a diff of commit1, commit2 plus the intermediate merge commits. What git does here is absolutely correct. But, my requirement is to only have the difference between commit1 & commit2 (without the intermediate merge commits).\n\nWe can definitely compare individual files between two commits in the following manner\ne.g., git diff commit1:file commit2:file\nbut, if I want to get the diff for all my files from commit1 to commit2 without considering totally unrelated files from the merge commits in between commit1 and commit2, I think it is a tedious process. Correct me if I am wrong. \n\nSo, my questions are.\n\nIs there a feature readily available in git that will compare just commit1 & commit2 without considering the intermediate merge commits?\n\n 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?\n\n\n\nThank You!\nSudheer"},{"id":"473260","messageId":"ZAl7JI3FZdUgrvkq@coredump.intra.peff.net","threadId":"59365","inReplyTo":"MN2PR15MB3454AE2CE41E79F2B260DDD3E1B59@MN2PR15MB3454.namprd15.prod.outlook.com","subject":"Re: git diff without intermediate commits","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-03-09T06:22:28Z","receivedAt":"2023-03-09T06:22:48Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 09, 2023 at 05:52:15AM +0000, Sudheer D wrote:\n\n> Is there a feature readily available in git that will compare just\n> commit1 & commit2 without considering the intermediate merge commits?\n\nNo. A diff is comparing two endpoints, without regards to the history.\nYou can choose different endpoints, but I don't think that really helps\nyour case (sometimes using the merge base as the preimage, which you can\naccess via the three-dot \"diff commit1...commit2\" can help, but I don't\nthink it does in your case).\n\n> If the answer to the above question to is 'no', if I am providing a\n> patch for the same for 'git diff' & 'git difftool' probably with a new\n> command line option, would you accept it?\n\nWe'd never say \"yes\" to accepting a patch without seeing it. I'm not\ninherently against such a feature, but I have trouble seeing how it\ncould even be implemented. You are really asking for a diff between the\nstate of \"commit2\" and \"commit1 as if it had been applied on top of\nthose merges\". But there is no guarantee that commit1 can be applied\nthere. If the merges touch some of the same lines, it won't work (and\nlikewise, if you try to do clever things like subtracting out bits of\nthe diff that come from the intermediate merges, it won't always work).\n\nYou can try something like:\n\n  # use a detached HEAD for looking around; we go\n  # the parent of commit2 here, which should be merge_commit_n\n  git checkout --detach $commit2^\n\n  # this may fail if commit1 conflicts with any of the merges\n  git cherry-pick $commit1\n\n  # but now we can see just the differences from commit1->commit2\n  git diff HEAD $commit2\n\nwhich will work sometimes, but I don't think it would be a good idea to\nbuild a feature around it.\n\n-Peff\n"},{"id":"473295","messageId":"xmqqwn3pc0fn.fsf@gitster.g","threadId":"59365","inReplyTo":"ZAl7JI3FZdUgrvkq@coredump.intra.peff.net","subject":"Re: git diff without intermediate commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-09T17:13:48Z","receivedAt":"2023-03-09T17:16:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> You can try something like:\n> ...\n> which will work sometimes,\n\nYup, that is how I would do the comparison, if I cannot undo these\n\"pointless merges from the upstream\".\n\n> but I don't think it would be a good idea to\n> build a feature around it.\n\nProbably.\n\nThanks.\n"}]}