{"thread":{"id":"45886","subject":"Script to rebase branches","startedAt":"2017-05-06T10:23:39Z","lastAt":"2017-05-10T04:47:00Z","messageCount":9,"participants":["Lars Schneider","Dennis Kaarsemaker","Jeff King","Johannes Schindelin","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"318928","messageId":"8D018370-79F9-450F-97AF-31EF4C95BA44@gmail.com","threadId":"45886","inReplyTo":null,"subject":"Script to rebase branches","fromName":"Lars Schneider","fromEmail":"larsxschneider@gmail.com","sentAt":"2017-05-06T10:23:32Z","receivedAt":"2017-05-06T10:23:39Z","isPatch":false,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"Hi,\n\nI am about to write a bash/sh script that helps me to rebase a bunch of \nbranches (e.g. select branches based on prefix, conflict resolution/\nrerere support, ...).\n\nI wonder if anyone has such a script already and is willing to share it.\n\nThanks,\nLars\n"},{"id":"318935","messageId":"1494090847.24179.7.camel@kaarsemaker.net","threadId":"45886","inReplyTo":"8D018370-79F9-450F-97AF-31EF4C95BA44@gmail.com","subject":"Re: Script to rebase branches","fromName":"Dennis Kaarsemaker","fromEmail":"dennis@kaarsemaker.net","sentAt":"2017-05-06T17:14:07Z","receivedAt":"2017-05-06T17:14:24Z","isPatch":false,"sender":{"key":"dennis@kaarsemaker.net","avatar":"https://avatars.githubusercontent.com/u/200649?v=4"},"body":"On Sat, 2017-05-06 at 12:23 +0200, Lars Schneider wrote:\n> Hi,\n> \n> I am about to write a bash/sh script that helps me to rebase a bunch of \n> branches (e.g. select branches based on prefix, conflict resolution/\n> rerere support, ...).\n> \n> I wonder if anyone has such a script already and is willing to share it.\n\nDscho's git garden shears perhaps?\n\nhttps://github.com/git-for-windows/build-extra/blob/master/shears.sh\n\nD.\n"},{"id":"319163","messageId":"20170509040943.j3n5li7fapiuvgbj@sigill.intra.peff.net","threadId":"45886","inReplyTo":"8D018370-79F9-450F-97AF-31EF4C95BA44@gmail.com","subject":"Re: Script to rebase branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-05-09T04:09:43Z","receivedAt":"2017-05-09T04:09:50Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, May 06, 2017 at 12:23:32PM +0200, Lars Schneider wrote:\n\n> I am about to write a bash/sh script that helps me to rebase a bunch of \n> branches (e.g. select branches based on prefix, conflict resolution/\n> rerere support, ...).\n> \n> I wonder if anyone has such a script already and is willing to share it.\n\nThis is what I use:\n\n  https://github.com/peff/git/blob/meta/rebase\n\nThere's no documentation in the script, but the commit message in its\nhistory should give a good sense of what each part does.\n\n-Peff\n"},{"id":"319179","messageId":"alpine.DEB.2.21.1.1705091244420.146734@virtualbox","threadId":"45886","inReplyTo":"20170509040943.j3n5li7fapiuvgbj@sigill.intra.peff.net","subject":"Re: Script to rebase branches","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2017-05-09T10:50:22Z","receivedAt":"2017-05-09T10:50:34Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 9 May 2017, Jeff King wrote:\n\n> On Sat, May 06, 2017 at 12:23:32PM +0200, Lars Schneider wrote:\n> \n> > I am about to write a bash/sh script that helps me to rebase a bunch of \n> > branches (e.g. select branches based on prefix, conflict resolution/\n> > rerere support, ...).\n> > \n> > I wonder if anyone has such a script already and is willing to share it.\n> \n> This is what I use:\n> \n>   https://github.com/peff/git/blob/meta/rebase\n> \n> There's no documentation in the script, but the commit message in its\n> history should give a good sense of what each part does.\n\nThat requires Meta/ to be checked out and up-to-date. I'd bet there are\nexactly two people who fall into that category.\n\nAlso, I see that you do not use worktrees. Otherwise your script would\nfail.\n\nWhen I still hoped to be able to get the rebase--helper related topic\nbranches in by August last year, I had grandiose plans to teach the\nsequencer not only to perform the Git garden shears' trick (i.e. recreate\nmerges), but also to optionally update local branches corresponding to the\nmerge commits, including updates to the worktrees that checked them out\n(if any).\n\nMaybe I'll still get around to do this, some time this year. And it'll\nprobably hit git.git by mid next year ;-)\n\nCiao,\nDscho\n"},{"id":"319180","messageId":"20170509110249.eluxns2zz5jqh42k@sigill.intra.peff.net","threadId":"45886","inReplyTo":"alpine.DEB.2.21.1.1705091244420.146734@virtualbox","subject":"Re: Script to rebase branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-05-09T11:02:50Z","receivedAt":"2017-05-09T11:02:59Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, May 09, 2017 at 12:50:22PM +0200, Johannes Schindelin wrote:\n\n> > This is what I use:\n> > \n> >   https://github.com/peff/git/blob/meta/rebase\n> > \n> > There's no documentation in the script, but the commit message in its\n> > history should give a good sense of what each part does.\n> \n> That requires Meta/ to be checked out and up-to-date. I'd bet there are\n> exactly two people who fall into that category.\n\nActually, it is not Junio's Meta that needs checked out, but rather the\n\"meta\" branch where you will find that \"rebase\" script. If other people\nfind them useful, the set of scripts could perhaps be transitioned to a\nnamespace that is appropriate to go into people's $PATH.\n\nI didn't really expect anybody to use it verbatim, though. I was\nproviding it more for inspiration.\n\n> Also, I see that you do not use worktrees. Otherwise your script would\n> fail.\n\nYes, the script predates the invention of worktrees by several years. I\nhave occasionally played with worktrees, but don't use them extensively\n(I'd usually use them for a one-off change, and then remove the\nworktree).\n\n> When I still hoped to be able to get the rebase--helper related topic\n> branches in by August last year, I had grandiose plans to teach the\n> sequencer not only to perform the Git garden shears' trick (i.e. recreate\n> merges), but also to optionally update local branches corresponding to the\n> merge commits, including updates to the worktrees that checked them out\n> (if any).\n\nI don't think I need anything that fancy. But simply checking \"is this\nchecked out in a worktree\" for each branch and then doing \"cd\n/path/to/worktree && git rebase\" instead of just \"git rebase $branch\"\nwould be enough, I think.\n\n(I'm assuming the problem you see is just that the directory running\nMeta/rebase cannot check out a branch that is checked out in another\nworktree).\n\n-Peff\n"},{"id":"319184","messageId":"alpine.DEB.2.21.1.1705091418540.146734@virtualbox","threadId":"45886","inReplyTo":"20170509110249.eluxns2zz5jqh42k@sigill.intra.peff.net","subject":"Re: Script to rebase branches","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2017-05-09T12:32:37Z","receivedAt":"2017-05-09T12:32:51Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 9 May 2017, Jeff King wrote:\n\n> On Tue, May 09, 2017 at 12:50:22PM +0200, Johannes Schindelin wrote:\n> \n> > > This is what I use:\n> > > \n> > >   https://github.com/peff/git/blob/meta/rebase\n> > > \n> > > There's no documentation in the script, but the commit message in its\n> > > history should give a good sense of what each part does.\n> > \n> > That requires Meta/ to be checked out and up-to-date. I'd bet there are\n> > exactly two people who fall into that category.\n> \n> Actually, it is not Junio's Meta that needs checked out, but rather the\n> \"meta\" branch where you will find that \"rebase\" script.\n\nOh, okay, I misunderstood that part, indeed.\n\n> If other people find them useful, the set of scripts could perhaps be\n> transitioned to a namespace that is appropriate to go into people's\n> $PATH.\n> \n> I didn't really expect anybody to use it verbatim, though. I was\n> providing it more for inspiration.\n\nI deem it part of Git's mission is to avoid forcing everybody to write\nscripts so specific to their own needs that they cannot be shared easily.\n\nThere are lots of parts in the interactive rebase, for example, that I do\nnot want to use myself. But enough users do to make it worthwhile to\nsupport in Git proper.\n\nLikewise, I assume that most developers work on one topic branch at a\ntime, until it is submitted as a Pull Request, and then move to the next\ntopic branch after the previous has been merged. But there are enough\nusers, I'd wager, including both you and me, who need to work on multiple\ntopics in parallel (for a plethora of reasons).\n\nCertainly there will be more developers with the need to rebase multiple\nbranches at once than there are developers needing to send patches via\nmail (and we support the latter operation with several top-level Git\ncommands).\n\nAnd that makes me believe that there is enough need for multi-branch\noperations that we should consider supporting them out of the box.\n\n> > Also, I see that you do not use worktrees. Otherwise your script would\n> > fail.\n> \n> Yes, the script predates the invention of worktrees by several years. I\n> have occasionally played with worktrees, but don't use them extensively\n> (I'd usually use them for a one-off change, and then remove the\n> worktree).\n\nI assumed as much, and I did not mean to criticise you for it. I was just\npointing out, implicitly, that the script has room for improvement to make\nit applicable to a broader audience.\n\nPersonally, I am a heavy user of worktrees, and once the vexing bug that\ncorrupts them by gc'ing in-use objects away.\n\nI kind of use them not only for developing the topic branches (as you\nknow, my patch series frequently see many iterations and many weeks going\nby before they hit home), but also as kind of a Pensive, where I keep\nthings I want to work on but do not have time right now. Some of my\nworktrees are both: they are topic branches in flight, and also remind me\nthat a certain topic was not yet accepted.\n\n> > When I still hoped to be able to get the rebase--helper related topic\n> > branches in by August last year, I had grandiose plans to teach the\n> > sequencer not only to perform the Git garden shears' trick (i.e.\n> > recreate merges), but also to optionally update local branches\n> > corresponding to the merge commits, including updates to the worktrees\n> > that checked them out (if any).\n> \n> I don't think I need anything that fancy. But simply checking \"is this\n> checked out in a worktree\" for each branch and then doing \"cd\n> /path/to/worktree && git rebase\" instead of just \"git rebase $branch\"\n> would be enough, I think.\n> \n> (I'm assuming the problem you see is just that the directory running\n> Meta/rebase cannot check out a branch that is checked out in another\n> worktree).\n\nI understand that you do not need anything that fancy. And you probably\nunderstand that I was not talking about your needs only, nor mine. I was\ntalking about a broader audience of power users with the need to work on\nmultiple branches in parallel, to automate things in order to make work\nmore fun.\n\nKinda like Git, you know?\n\nCiao,\nDscho\n"},{"id":"319234","messageId":"xmqq8tm51wch.fsf@gitster.mtv.corp.google.com","threadId":"45886","inReplyTo":"20170509110249.eluxns2zz5jqh42k@sigill.intra.peff.net","subject":"Re: Script to rebase branches","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-05-09T22:47:26Z","receivedAt":"2017-05-09T22:47:32Z","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>> That requires Meta/ to be checked out and up-to-date. I'd bet there are\n>> exactly two people who fall into that category.\n>\n> Actually, it is not Junio's Meta that needs checked out, but rather the\n> \"meta\" branch where you will find that \"rebase\" script. If other people\n> find them useful, the set of scripts could perhaps be transitioned to a\n> namespace that is appropriate to go into people's $PATH.\n>\n> I didn't really expect anybody to use it verbatim, though. I was\n> providing it more for inspiration.\n>\n>> Also, I see that you do not use worktrees. Otherwise your script would\n>> fail.\n>\n> Yes, the script predates the invention of worktrees by several years. I\n> have occasionally played with worktrees, but don't use them extensively\n> (I'd usually use them for a one-off change, and then remove the\n> worktree).\n\nI check out a different Meta/ at the top-level of my working tree\nwhen working on Git, but I do use an equivalent of \"worktree\" to\nhave separate build areas for four integration branches.  It is\ntrivial to check out Meta/ just once to the primary working tree and\nsymlink it to others ;-)\n\nOne thing that struck me odd about your \"rebase\" script was that it\ndidn't seem to have a special provision to handle a topic that\nbuilds on another topic. I saw toposort, but is that sufficient?\n"},{"id":"319248","messageId":"20170510043646.seh73ejdperb2ym7@sigill.intra.peff.net","threadId":"45886","inReplyTo":"xmqq8tm51wch.fsf@gitster.mtv.corp.google.com","subject":"Re: Script to rebase branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-05-10T04:36:46Z","receivedAt":"2017-05-10T04:36:55Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 10, 2017 at 07:47:26AM +0900, Junio C Hamano wrote:\n\n> > Yes, the script predates the invention of worktrees by several years. I\n> > have occasionally played with worktrees, but don't use them extensively\n> > (I'd usually use them for a one-off change, and then remove the\n> > worktree).\n> \n> I check out a different Meta/ at the top-level of my working tree\n> when working on Git, but I do use an equivalent of \"worktree\" to\n> have separate build areas for four integration branches.  It is\n> trivial to check out Meta/ just once to the primary working tree and\n> symlink it to others ;-)\n\nYeah, I guess I'd need to do that, too, if I used worktrees extensively.\nI think the specific problem with the rebase script is just that it\nexpects to be able to checkout all the branches.\n\n> One thing that struck me odd about your \"rebase\" script was that it\n> didn't seem to have a special provision to handle a topic that\n> builds on another topic. I saw toposort, but is that sufficient?\n\nIt topo-sorts so that a single run rebases everything (otherwise you may\nneed to run N times, where N is the deepest dependency chain). But it\nalso uses reflogs to try to find the fork point when the upstream topic\nhas been rebased.\n\nThe logic is in find_base(). Once upon a time it used \"git pull\n--rebase\", but there were some complications. These days I think it\ncould probably use \"rebase --fork-point\", but I just never got around to\ntesting it.\n\n-Peff\n"},{"id":"319249","messageId":"20170510044645.hqxkzljajaifwwsl@sigill.intra.peff.net","threadId":"45886","inReplyTo":"alpine.DEB.2.21.1.1705091418540.146734@virtualbox","subject":"Re: Script to rebase branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-05-10T04:46:45Z","receivedAt":"2017-05-10T04:47:00Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, May 09, 2017 at 02:32:37PM +0200, Johannes Schindelin wrote:\n\n> > I didn't really expect anybody to use it verbatim, though. I was\n> > providing it more for inspiration.\n> \n> I deem it part of Git's mission is to avoid forcing everybody to write\n> scripts so specific to their own needs that they cannot be shared easily.\n\nSure. I'd be happy if somebody used it as inspiration to make a tool for\neverybody, too.\n\nThe two main reasons I don't polish and try to share the bits in my\nMeta/ more widely are:\n\n  1. Most of them are as much policy as they are implementation logic.\n     So either you buy in completely to the worldview that I've assumed\n     in my tools, or you end up fighting the tool (and by the time you\n     make the tool configurable enough to handle all world-views, you\n     haven't really helped anybody).\n\n     I think the best thing to do with those logic bits is to add them\n     as much as possible to Git itself (e.g., as command-line options).\n     That keeps any personal scripts as thin wrappers that specify the\n     policy.\n\n  2. Some of the features are really powerful but also really dangerous.\n     For example, my \"rebase\" script (which rebases all my topics) and\n     my \"private\" script (which builds my daily \"private\" version of Git\n     to run) both write a shell snippet into $GIT_DIR/continue.\n\n     And then I have a git-continue alias that looks like this:\n\n        #!/bin/sh\n        SUBDIRECTORY_OK=Yes\n        . git-sh-setup\n        cd_to_toplevel\n\n        if test -f \"$GIT_DIR/continue\"; then\n          eval \"$(cat \"$GIT_DIR/continue\")\"\n        elif test -d \"$GIT_DIR/rebase-merge\"; then\n          git rebase --continue\n        elif test -d \"$GIT_DIR/rebase-apply\"; then\n          if test -f \"$GIT_DIR/rebase-apply/applying\"; then\n            git am --continue\n          else\n            git rebase --continue\n          fi\n        elif test -f \"$GIT_DIR/CHERRY_PICK_HEAD\"; then\n          git cherry-pick --continue\n        else\n          echo >&2 \"nothing to continue\"\n          exit 1\n        fi\n\n     So when I run \"git continue\" it magically tries to pick up the\n     operation in progress keep going. When it works, it works\n     beautifully. But when it doesn't...well, you can dig yourself into\n     a pretty confusing situation. It's worth it for me, because I can\n     dig myself out. But I'm not sure it's something I'd encourage other\n     people to use.\n\n-Peff\n"}]}