{"thread":{"id":"60350","subject":"How to combine multiple commit diffs?","startedAt":"2023-10-12T12:01:11Z","lastAt":"2023-10-18T13:05:56Z","messageCount":5,"participants":["ZheNing Hu","Junio C Hamano","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"483146","messageId":"CAOLTT8RzcENBx9NKffHReVKJAho89TCO7W2SPBX8sb2tEU84Gw@mail.gmail.com","threadId":"60350","inReplyTo":null,"subject":"How to combine multiple commit diffs?","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2023-10-12T12:00:25Z","receivedAt":"2023-10-12T12:01:11Z","isPatch":false,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Hi everyone,\n\nOur company wants to design a \"small-batch\" code review feature.\nSimply put, this \"small-batch\" means being able to treat multiple\nrelated commits within a MergeRequest as an independent \"small\" code\nreview.\n\nLet me give you an example: We have five commits: A1, B, A2, C, A3.\nAmong them, A1, A2, and A3 are multiple commits for the same feature.\nSo when the user selects these commits, the page will return a\n\"combine diff\" that combines them together.\n\nA1       B A2 A3 C\n*--------*----*-----*-------* (branch)\n \\ A1'        \\ A2'  \\ A3'\n  *------------*------*------- (small branch code review)\n\nThis may seem similar to cherry-picking a few commits from a pile of\ncommits, but in fact, we do not expect to actually perform\ncherry-picking.\n\nDo you have any suggestions on how we can merge a few commits together\nand display the diff? The only reference we have is the non-open\nsource platform, JetBrains Space CodeReview, they support selecting\nmultiple commits for CodeReview. [1], .\n\n[1]: https://www.jetbrains.com/help/space/review-code.html#code-review-example\n\nThanks,\n--\nZheNing Hu\n"},{"id":"483158","messageId":"xmqqpm1jg4dk.fsf@gitster.g","threadId":"60350","inReplyTo":"CAOLTT8RzcENBx9NKffHReVKJAho89TCO7W2SPBX8sb2tEU84Gw@mail.gmail.com","subject":"Re: How to combine multiple commit diffs?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-10-12T17:03:19Z","receivedAt":"2023-10-12T17:03:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"ZheNing Hu <adlternative@gmail.com> writes:\n\n> This may seem similar to cherry-picking a few commits from a pile of\n> commits, but in fact, we do not expect to actually perform\n> cherry-picking.\n\nIf you said \"We do not want to\", I may be sympathetic, but it is\ncurious that you said \"We do not expect to\", which hints that you\nalready have some implementation in mind.\n\nWhether you use a checkout of the history to a working tree and\nperform a series of \"git cherry-pick\" to implement it, or use the\n\"git replay\" machinery to perform them in-core, at the conceptual\nlevel, you would need to pick a base commit and apply the effect of\nthose commits you would want to look at on top of that base in\nsequence, before you can see the combined change, no?\n\nPuzzled.\n"},{"id":"483160","messageId":"22688989-1b51-4989-b92d-5a5891ec9265@kdbg.org","threadId":"60350","inReplyTo":"CAOLTT8RzcENBx9NKffHReVKJAho89TCO7W2SPBX8sb2tEU84Gw@mail.gmail.com","subject":"Re: How to combine multiple commit diffs?","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2023-10-12T16:41:25Z","receivedAt":"2023-10-12T17:21:33Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"[For general support questions, please address only the mailing list.\nIt's not necessary to bother the maintainer personally. Though, I'll not\nremove him from Cc, yet, as to comply with this ML's etiquette.]\n\nAm 12.10.23 um 14:00 schrieb ZheNing Hu:\n> Hi everyone,\n> \n> Our company wants to design a \"small-batch\" code review feature.\n> Simply put, this \"small-batch\" means being able to treat multiple\n> related commits within a MergeRequest as an independent \"small\" code\n> review.\n> \n> Let me give you an example: We have five commits: A1, B, A2, C, A3.\n> Among them, A1, A2, and A3 are multiple commits for the same feature.\n> So when the user selects these commits, the page will return a\n> \"combine diff\" that combines them together.\n> \n> A1       B A2 A3 C\n> *--------*----*-----*-------* (branch)\n>  \\ A1'        \\ A2'  \\ A3'\n>   *------------*------*------- (small branch code review)\n> \n> This may seem similar to cherry-picking a few commits from a pile of\n> commits, but in fact, we do not expect to actually perform\n> cherry-picking.\n> \n> Do you have any suggestions on how we can merge a few commits together\n> and display the diff? The only reference we have is the non-open\n> source platform, JetBrains Space CodeReview, they support selecting\n> multiple commits for CodeReview. [1], .\n\n\nTake a step back. Then ask: What are the consequences of the review?\nWhat if the result is: the feature is perfect, we want it merged,\nhowever, we cannot, because we do not want commit B. What if the result\nis the opposite? You need B, but you can't merge it because the feature\nis not ready, yet?\n\nYou are looking for a technical workaround for a non-optimal workflow.\nIf A1,A2,A3 are a feature on their own, they, and only they, should be\nin their own feature branch.\n\nSo, I would say, the best solution is to reorder the commits in a better\nmanageable order. You do know about git rebase --interactive, don't you?\n\n-- Hannes\n\n"},{"id":"483400","messageId":"CAOLTT8Ti_HMtCKnag0dGk8jdRQ_7mtWys8f9U0gKjP9UzcVyag@mail.gmail.com","threadId":"60350","inReplyTo":"22688989-1b51-4989-b92d-5a5891ec9265@kdbg.org","subject":"Re: How to combine multiple commit diffs?","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2023-10-18T12:47:55Z","receivedAt":"2023-10-18T12:48:11Z","isPatch":false,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Johannes Sixt <j6t@kdbg.org> 于2023年10月13日周五 00:41写道：\n>\n> [For general support questions, please address only the mailing list.\n> It's not necessary to bother the maintainer personally. Though, I'll not\n> remove him from Cc, yet, as to comply with this ML's etiquette.]\n>\n\nOK... I get it.\n\n> Am 12.10.23 um 14:00 schrieb ZheNing Hu:\n> > Hi everyone,\n> >\n> > Our company wants to design a \"small-batch\" code review feature.\n> > Simply put, this \"small-batch\" means being able to treat multiple\n> > related commits within a MergeRequest as an independent \"small\" code\n> > review.\n> >\n> > Let me give you an example: We have five commits: A1, B, A2, C, A3.\n> > Among them, A1, A2, and A3 are multiple commits for the same feature.\n> > So when the user selects these commits, the page will return a\n> > \"combine diff\" that combines them together.\n> >\n> > A1       B A2 A3 C\n> > *--------*----*-----*-------* (branch)\n> >  \\ A1'        \\ A2'  \\ A3'\n> >   *------------*------*------- (small branch code review)\n> >\n> > This may seem similar to cherry-picking a few commits from a pile of\n> > commits, but in fact, we do not expect to actually perform\n> > cherry-picking.\n> >\n> > Do you have any suggestions on how we can merge a few commits together\n> > and display the diff? The only reference we have is the non-open\n> > source platform, JetBrains Space CodeReview, they support selecting\n> > multiple commits for CodeReview. [1], .\n>\n>\n> Take a step back. Then ask: What are the consequences of the review?\n> What if the result is: the feature is perfect, we want it merged,\n> however, we cannot, because we do not want commit B. What if the result\n> is the opposite? You need B, but you can't merge it because the feature\n> is not ready, yet?\n>\n\nThe CodeReview here is only expected to review the Diff changes\n (just like jetbrains Space). If it is truly blocked by B, users should\nunderstand to remove B or cherrypick A1, A2, A3 into a new branch.\n\n\n> You are looking for a technical workaround for a non-optimal workflow.\n> If A1,A2,A3 are a feature on their own, they, and only they, should be\n> in their own feature branch.\n>\n\nI have to admit that this is addressing the issue for users who are not\nvery familiar with the git workflow, as they might add 70 commits in a\nCodeReview.\nMy goal is to enable these users to display the diff of multiple commits\nthat they consider to be related together.\n\n> So, I would say, the best solution is to reorder the commits in a better\n> manageable order. You do know about git rebase --interactive, don't you?\n>\n\nIt would be great if users knew how to do that, and I wouldn't have to\nexplore such unconventional technical solutions :(\n\n> -- Hannes\n>\n"},{"id":"483402","messageId":"CAOLTT8RUAm0cDdqF8Nu=3sZZOMKom5R0jXjNm-=xXXaYJZBkew@mail.gmail.com","threadId":"60350","inReplyTo":"xmqqpm1jg4dk.fsf@gitster.g","subject":"Re: How to combine multiple commit diffs?","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2023-10-18T13:05:40Z","receivedAt":"2023-10-18T13:05:56Z","isPatch":false,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Junio C Hamano <gitster@pobox.com> 于2023年10月13日周五 01:03写道：\n>\n> ZheNing Hu <adlternative@gmail.com> writes:\n>\n> > This may seem similar to cherry-picking a few commits from a pile of\n> > commits, but in fact, we do not expect to actually perform\n> > cherry-picking.\n>\n> If you said \"We do not want to\", I may be sympathetic, but it is\n> curious that you said \"We do not expect to\", which hints that you\n> already have some implementation in mind.\n>\n\nOur code platform has the ability to cherry-pick (by libgit2),\nbut using cherry-pick to merge and display the diff of the same feature\nmight be challenging for users (as it can easily meet conflicts).\n\n> Whether you use a checkout of the history to a working tree and\n> perform a series of \"git cherry-pick\" to implement it, or use the\n> \"git replay\" machinery to perform them in-core, at the conceptual\n> level, you would need to pick a base commit and apply the effect of\n> those commits you would want to look at on top of that base in\n> sequence, before you can see the combined change, no?\n>\n\nYes, \"cherry pick\" and \"rebase -i\" are indeed the most natural\napproaches to merging and displaying diffs. It's unfortunate\nthat we didn't choose to use them in our technical selection.\n\n> Puzzled.\n\nI can only roughly estimate how Jetbrains Space solves this problem:\n\n1. The user selects a few non-consecutive commits in the commit list.\n2. The backend service will calculate the set of modified files for the selected\n    commits in the CodeReview.\n3. The backend service it calculates the latest commit and oldest parent commit\n    of each file that introduced the diff in the selected commits.\n4. it calculates the file diff using these two commits.\n5. Afterwards, there is some way to filter out the intermediate, non-selected\n   commits that modified the files. I don't quite understand this\nstep, it feels rather hacker-like.\n"}]}