{"thread":{"id":"17042","subject":"collapsing commits with rebase","startedAt":"2009-01-08T00:08:44Z","lastAt":"2009-01-10T10:34:57Z","messageCount":12,"participants":["Geoff Russell","Johannes Schindelin","Boyd Stephen Smith Jr.","Miklos Vajna","Sitaram Chamarty","nadim khemir"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"99637","messageId":"93c3eada0901071608r190a723bma502b68c4ab81a08@mail.gmail.com","threadId":"17042","inReplyTo":null,"subject":"collapsing commits with rebase","fromName":"Geoff Russell","fromEmail":"geoffrey.russell@gmail.com","sentAt":"2009-01-08T00:08:44Z","receivedAt":"2009-01-08T00:08:44Z","isPatch":false,"sender":{"key":"geoffrey.russell@gmail.com","avatar":"https://gravatar.com/avatar/c30f497ccfa6bf06d86f30bd2ba092a2dd124c61c6bc902f7cb5c3f6486947de?d=mp&s=160"},"body":"Dear gits,\n\nI have a series of commits:\n\n    A---B---C---D---E---F\n\nI want to collapse B---C---D into one single commit. git rebase -i B  will allow\nme to do this, but I'm looking for a non-interactive incantation.\n\nCheers,\nGeoff Russell\n\n\nP.S. The context is a program that performs a single high level\noperation on a repository\nas a series of commits but then wants to turn  it back into a single\ncommit without\nuser intervention so it subsequently looks like a single op in the history.\n"},{"id":"99642","messageId":"alpine.DEB.1.00.0901080144270.30769@pacific.mpi-cbg.de","threadId":"17042","inReplyTo":"93c3eada0901071608r190a723bma502b68c4ab81a08@mail.gmail.com","subject":"Re: collapsing commits with rebase","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-08T00:45:55Z","receivedAt":"2009-01-08T00:45:55Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 8 Jan 2009, Geoff Russell wrote:\n\n> Dear gits,\n> \n> I have a series of commits:\n> \n>     A---B---C---D---E---F\n> \n> I want to collapse B---C---D into one single commit. git rebase -i B \n> will allow me to do this, but I'm looking for a non-interactive \n> incantation.\n\nYou set GIT_EDITOR to a script ;-)\n\nAlternatively, something like this should work for you:\n\n\t$ git checkout A\n\t$ git read-tree -u -m D\n\t$ git commit -m \"My message\"\n\t$ git cherry-pick E\n\t$ git cherry-pick F\n\nHth,\nDscho\n"},{"id":"99654","messageId":"93c3eada0901071759u2496835dy134d92613bf4244b@mail.gmail.com","threadId":"17042","inReplyTo":"alpine.DEB.1.00.0901080144270.30769@pacific.mpi-cbg.de","subject":"Re: collapsing commits with rebase","fromName":"Geoff Russell","fromEmail":"geoffrey.russell@gmail.com","sentAt":"2009-01-08T01:59:09Z","receivedAt":"2009-01-08T01:59:09Z","isPatch":false,"sender":{"key":"geoffrey.russell@gmail.com","avatar":"https://gravatar.com/avatar/c30f497ccfa6bf06d86f30bd2ba092a2dd124c61c6bc902f7cb5c3f6486947de?d=mp&s=160"},"body":"On Thu, Jan 8, 2009 at 11:15 AM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Thu, 8 Jan 2009, Geoff Russell wrote:\n>\n>> Dear gits,\n>>\n>> I have a series of commits:\n>>\n>>     A---B---C---D---E---F\n>>\n>> I want to collapse B---C---D into one single commit. git rebase -i B\n>> will allow me to do this, but I'm looking for a non-interactive\n>> incantation.\n>\n> You set GIT_EDITOR to a script ;-)\n\nThis is plan B.\n\n>\n> Alternatively, something like this should work for you:\n>\n>        $ git checkout A\n>        $ git read-tree -u -m D\n>        $ git commit -m \"My message\"\n>        $ git cherry-pick E\n>        $ git cherry-pick F\n\nPlan B is looking good, because I'd generally like the commit message to be the\nconcatenation of the messages for B,C and D.\n\nMany thanks.\n\nGeoff.\n"},{"id":"99655","messageId":"200901072011.37299.bss@iguanasuicide.net","threadId":"17042","inReplyTo":"93c3eada0901071608r190a723bma502b68c4ab81a08@mail.gmail.com","subject":"Re: collapsing commits with rebase","fromName":"Boyd Stephen Smith Jr.","fromEmail":"bss@iguanasuicide.net","sentAt":"2009-01-08T02:11:32Z","receivedAt":"2009-01-08T02:11:32Z","isPatch":false,"sender":{"key":"bss@iguanasuicide.net","avatar":"https://gravatar.com/avatar/84b95eeff194b816c1568b1339e63e4b229825298664a9037b9f1ec713ead1e3?d=mp&s=160"},"body":"On Wednesday 2009 January 07 18:08:44 Geoff Russell wrote:\n>I have a series of commits:\n>\n>    A---B---C---D---E---F\n\nAssuming you also have a ref (e.g. Foo) that points to F:\ngit checkout sha(B)\ngit merge -s sha(D)\ngit rebase --onto $(cat .git/HEAD) sha(E) Foo\n\nshould do what you want.\n\nAfter the checkout:\nA -> B [HEAD] -> C -> D -> E -> F [Foo]\n(detached HEAD)\n\nAfter the merge:\nA -> B -> C -> D -> E -> F [Foo]\n     |\n     +--> [HEAD]\n(detached HEAD)\n\nAfter the rebase:\nA -> B -> E' -> F' [Foo, HEAD]\n     |\n     +--> C -> D -> E -> F\n(C, D, E, and F will be pruned at some point)\n-- \nBoyd Stephen Smith Jr.                     ,= ,-_-. =. \nbss@iguanasuicide.net                     ((_/)o o(\\_))\nICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' \nhttp://iguanasuicide.net/                      \\_/     \n"},{"id":"99658","messageId":"20090108023224.GU21154@genesis.frugalware.org","threadId":"17042","inReplyTo":"200901072011.37299.bss@iguanasuicide.net","subject":"Re: collapsing commits with rebase","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2009-01-08T02:32:24Z","receivedAt":"2009-01-08T02:32:24Z","isPatch":false,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Wed, Jan 07, 2009 at 08:11:32PM -0600, \"Boyd Stephen Smith Jr.\" <bss@iguanasuicide.net> wrote:\n> git merge -s sha(D)\n\nYou probably mean --squash here, -s stands for --strategy - and I *hope*\nyou don't have git-sha(D) in your PATH, as a custom merge strategy. ;-)\n"},{"id":"99659","messageId":"200901072039.12631.bss@iguanasuicide.net","threadId":"17042","inReplyTo":"20090108023224.GU21154@genesis.frugalware.org","subject":"Re: collapsing commits with rebase","fromName":"Boyd Stephen Smith Jr.","fromEmail":"bss@iguanasuicide.net","sentAt":"2009-01-08T02:39:07Z","receivedAt":"2009-01-08T02:39:07Z","isPatch":false,"sender":{"key":"bss@iguanasuicide.net","avatar":"https://gravatar.com/avatar/84b95eeff194b816c1568b1339e63e4b229825298664a9037b9f1ec713ead1e3?d=mp&s=160"},"body":"On Wednesday 2009 January 07 20:32:24 Miklos Vajna wrote:\n>On Wed, Jan 07, 2009 at 08:11:32PM -0600, \"Boyd Stephen Smith Jr.\" \n<bss@iguanasuicide.net> wrote:\n>> git merge -s sha(D)\n>\n>You probably mean --squash here, -s stands for --strategy - and I *hope*\n>you don't have git-sha(D) in your PATH, as a custom merge strategy. ;-)\n\nOops.  Yes.  My mistake.\n-- \nBoyd Stephen Smith Jr.                     ,= ,-_-. =. \nbss@iguanasuicide.net                     ((_/)o o(\\_))\nICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' \nhttp://iguanasuicide.net/                      \\_/     \n"},{"id":"99670","messageId":"slrngmav3b.20e.sitaramc@sitaramc.homelinux.net","threadId":"17042","inReplyTo":"200901072011.37299.bss@iguanasuicide.net","subject":"Re: collapsing commits with rebase","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2009-01-08T04:09:15Z","receivedAt":"2009-01-08T04:09:15Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"On 2009-01-08, Boyd Stephen Smith Jr. <bss@iguanasuicide.net> wrote:\n>>    A---B---C---D---E---F\n\n> Assuming you also have a ref (e.g. Foo) that points to F:\n> git checkout sha(B)\n> git merge -s sha(D)\n\nI think you now need to do a commit (assuming you meant\n\"--squash\").  Squash will not commit, and your rebase below\n(if it runs at all -- I suspect it will refuse to run) will\nhard reset to B, the current HEAD.  IOW\n\n> After the merge:\n> A -> B -> C -> D -> E -> F [Foo]\n>      |\n>      +--> [HEAD]\n\nis not true.  You have C+D in the index, not in the tree.\n\n> git rebase --onto $(cat .git/HEAD) sha(E) Foo\n\nAlso I think you have an off-by-one error here; you need\nsha(D) in that rebase command, not sha(E).\n\nAs your rebase command stands, you will lose commit E\ncompletely; neither the merge nor the rebase will pick it\nup.\n\n[Haven't tested, but I *think* I understand rebase well\nenough now to say so...]\n"},{"id":"99671","messageId":"200901072224.04906.bss@iguanasuicide.net","threadId":"17042","inReplyTo":"slrngmav3b.20e.sitaramc@sitaramc.homelinux.net","subject":"Re: collapsing commits with rebase","fromName":"Boyd Stephen Smith Jr.","fromEmail":"bss@iguanasuicide.net","sentAt":"2009-01-08T04:23:59Z","receivedAt":"2009-01-08T04:23:59Z","isPatch":false,"sender":{"key":"bss@iguanasuicide.net","avatar":"https://gravatar.com/avatar/84b95eeff194b816c1568b1339e63e4b229825298664a9037b9f1ec713ead1e3?d=mp&s=160"},"body":"On Wednesday 2009 January 07 22:09:15 Sitaram Chamarty wrote:\n>[Haven't tested, but I *think* I understand rebase well\n>enough now to say so...]\n\nProbably understand it better than me.  I just haven't needed to use it for \nthis that much.  This also might not be much better than setting GIT_PAGER to \na script, but it seems less fragile to me.\n-- \nBoyd Stephen Smith Jr.                     ,= ,-_-. =. \nbss@iguanasuicide.net                     ((_/)o o(\\_))\nICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' \nhttp://iguanasuicide.net/                      \\_/     \n"},{"id":"99691","messageId":"93c3eada0901080149m3c349e6bx33b58d653fd43b48@mail.gmail.com","threadId":"17042","inReplyTo":"200901072039.12631.bss@iguanasuicide.net","subject":"Re: collapsing commits with rebase","fromName":"Geoff Russell","fromEmail":"geoffrey.russell@gmail.com","sentAt":"2009-01-08T09:49:16Z","receivedAt":"2009-01-08T09:49:16Z","isPatch":false,"sender":{"key":"geoffrey.russell@gmail.com","avatar":"https://gravatar.com/avatar/c30f497ccfa6bf06d86f30bd2ba092a2dd124c61c6bc902f7cb5c3f6486947de?d=mp&s=160"},"body":"On 1/8/09, Boyd Stephen Smith Jr. <bss@iguanasuicide.net> wrote:\n> On Wednesday 2009 January 07 20:32:24 Miklos Vajna wrote:\n>  >On Wed, Jan 07, 2009 at 08:11:32PM -0600, \"Boyd Stephen Smith Jr.\"\n>  <bss@iguanasuicide.net> wrote:\n>  >> git merge -s sha(D)\n>  >\n>  >You probably mean --squash here, -s stands for --strategy - and I *hope*\n>  >you don't have git-sha(D) in your PATH, as a custom merge strategy. ;-)\n>\n\nMany thanks, now I have plenty of ways to think about!\n\nCheers,\nGeoff.\n"},{"id":"99695","messageId":"alpine.DEB.1.00.0901081205120.30769@pacific.mpi-cbg.de","threadId":"17042","inReplyTo":"93c3eada0901071759u2496835dy134d92613bf4244b@mail.gmail.com","subject":"Re: collapsing commits with rebase","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-08T11:07:09Z","receivedAt":"2009-01-08T11:07:09Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 8 Jan 2009, Geoff Russell wrote:\n\n> On Thu, Jan 8, 2009 at 11:15 AM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n>\n> > Alternatively, something like this should work for you:\n> >\n> >        $ git checkout A\n> >        $ git read-tree -u -m D\n> >        $ git commit -m \"My message\"\n> >        $ git cherry-pick E\n> >        $ git cherry-pick F\n> \n> Plan B is looking good, because I'd generally like the commit message to \n> be the concatenation of the messages for B,C and D.\n\nReplace the commit call by this:\n\n\t$ for commit in B C D\n\t  do\n\t\tgit cat-file commit $commit | sed '1,/^$/d'\n\t\t# possibly add an empty line between the commit messages,\n\t\t# git commit will strip away empty lines at the end.\n\t  done |\n\t  git commit -F -\n\nHth,\nDscho\n"},{"id":"99864","messageId":"200901101126.43650.nadim@khemir.net","threadId":"17042","inReplyTo":"93c3eada0901071608r190a723bma502b68c4ab81a08@mail.gmail.com","subject":"Re: collapsing commits with rebase","fromName":"nadim khemir","fromEmail":"nadim@khemir.net","sentAt":"2009-01-10T10:26:43Z","receivedAt":"2009-01-10T10:26:43Z","isPatch":false,"sender":{"key":"nadim@khemir.net","avatar":null},"body":"On Thursday 08 January 2009 01.08.44 Geoff Russell wrote:\n> Dear gits,\n>\n> I have a series of commits:\n>\n>     A---B---C---D---E---F\n>\n> I want to collapse B---C---D into one single commit. git rebase -i B  will\n> allow me to do this, but I'm looking for a non-interactive incantation.\n\nHi Geoff, Could you please share with use the final (tested) solution? I'd be \ninterrested to see how you did implement plan B if you did.\n\nCheers, Nadim.\n"},{"id":"99867","messageId":"93c3eada0901100234w37724281q424698f452b0148b@mail.gmail.com","threadId":"17042","inReplyTo":"alpine.DEB.1.00.0901081205120.30769@pacific.mpi-cbg.de","subject":"Re: collapsing commits with rebase","fromName":"Geoff Russell","fromEmail":"geoffrey.russell@gmail.com","sentAt":"2009-01-10T10:34:57Z","receivedAt":"2009-01-10T10:34:57Z","isPatch":false,"sender":{"key":"geoffrey.russell@gmail.com","avatar":"https://gravatar.com/avatar/c30f497ccfa6bf06d86f30bd2ba092a2dd124c61c6bc902f7cb5c3f6486947de?d=mp&s=160"},"body":"On 1/8/09, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>  On Thu, 8 Jan 2009, Geoff Russell wrote:\n>\n>  > On Thu, Jan 8, 2009 at 11:15 AM, Johannes Schindelin\n>  > <Johannes.Schindelin@gmx.de> wrote:\n>  >\n>\n> > > Alternatively, something like this should work for you:\n>  > >\n>  > >        $ git checkout A\n>  > >        $ git read-tree -u -m D\n>  > >        $ git commit -m \"My message\"\n>  > >        $ git cherry-pick E\n>  > >        $ git cherry-pick F\n>  >\n>  > Plan B is looking good, because I'd generally like the commit message to\n>  > be the concatenation of the messages for B,C and D.\n>\n>\n> Replace the commit call by this:\n>\n>         $ for commit in B C D\n>           do\n>                 git cat-file commit $commit | sed '1,/^$/d'\n>                 # possibly add an empty line between the commit messages,\n>                 # git commit will strip away empty lines at the end.\n>           done |\n>           git commit -F -\n>\n>  Hth,\n>  Dscho\n\nThat makes sense, many thanks.\n\nCheers,\nGeoff.\n"}]}