{"thread":{"id":"63981","subject":"[Feature request] allow git rebase while already rebasing","startedAt":"2025-08-18T19:29:48Z","lastAt":"2025-08-18T20:46:08Z","messageCount":3,"participants":["Isaac Oscar Gariano","Oswald Buddenhagen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"524359","messageId":"SYBP282MB29631756F18E53B16F2550848C31A@SYBP282MB2963.AUSP282.PROD.OUTLOOK.COM","threadId":"63981","inReplyTo":null,"subject":"[Feature request] allow git rebase while already rebasing","fromName":"Isaac Oscar Gariano","fromEmail":"isaacoscar@live.com.au","sentAt":"2025-08-18T19:29:45Z","receivedAt":"2025-08-18T19:29:48Z","isPatch":false,"sender":{"key":"isaacoscar@live.com.au","avatar":null},"body":"I've been doing a lot of interactive rebases lately, and I often edit a commit, continue to the next step of the rebase, and then realise theres' a change a forgot to make.\nNow usually, when I forget to do something in a commit, I do \"git rebase -ir <bad-commit>\", and then change the first \"pick\" line to \"edit\". Make changes, then \"git add -u && git rebase --continue\".\nUnfortunately, if I'm already in the process of a rebase it doesn't work: you can't have nested rebases.\n\nI suggest removing this limitation, basically the idea is that if you do \"git rebase\" while you are already rebasing, it performs the following:\n* it computes a new todo list as normal, and then prepends it to the current todo list\n* it does a 'git reset --hard <start point>' like normal\n\nObviously there needs to be some limitations (e.g. it will probably only work on the merge backend).\n\nIf anyone knows of any tools that let you do this, it would be great.\nIf people think it's likely to be accepted, I may make the changes to git myself to do this, but otherwise it's less work for me to just write a wrapper shell script with the features I actually might use.\n\nIn particular, the rest of this email is a fish script which demonstrates that one can actually do this:\n\t# This will likely not work properly in many cases, it's just a proof of concept\n\tif test (count $argv) -lt 1\n\t\techo \"USAGE: double-rebase <upstream> [<branch> [<new base> <rebase options>...]]\"\n                echo \"which is like \\\"git rebase <upstream> <branch> --onto <new base> --interactive <rebase options>\\\".\"\n                echo \"but for when you are already in a rebase\"\n\t\texit 1; end\n\n\t# Same defaults as git rebase\n\tif not set -q argv[2]\n\t\tset argv[2] HEAD; end\n\tif not set -q argv[3]\n\t\tset argv[3] $argv[1]; end\n\n\tset MAIN (git rev-parse --git-path rebase-merge)\n\tif not test -e $MAIN\n\t\techo \"fatal: rebase --merge not in progress\"\n\t\texit 1; end\n\n\t# Make a backup of the current rebase\n\tset BACKUP (git rev-parse --git-path rebase-backup)\n\tif test -e $BACKUP\n\t\techo \"fatal: $BACKUP already exists (did a previouse double-rebase crash?)\"; end\n\tmv $MAIN $BACKUP || exit\n\n\t# This 'GIT_SEQUENCE_EDITOR' command will print the file to stdout, with \n\t# lines starting with a # striped, and then blank the file.\n\t# Because the file gets blanked, git rebase won't actually do anything\n\t# to the repo.\n\tGIT_SEQUENCE_EDITOR=\"f () { rg -v '^#' \\\"\\$@\\\"; echo > \\\"\\$@\\\"; }; f\" \\\n\t\tgit rebase -i $argv[4..] --onto=$argv[2] -- $argv[1] $argv[2] > $BACKUP/double-rebase-todo 2>$BACKUP/double-rebase-err\n\n\tmv $BACKUP $MAIN || exit\n\n\t# If the above rebase print anything to stderr other than an error about the file, being empty, something when wrong\n\tset -l stat $status\n\tif not diff -q $MAIN/double-rebase-err (echo \"error: nothing to do\" | psub)>/dev/null\n\t\tcat $MAIN/double-rebase-err >&2\n\t\texit $stat\n\tend\n\n\t# Stupid hack to make the new labels unique\n\tset new_labels (rg '^\\s*(l|label)\\s+([^ \\t#]+)' -or '$2' $MAIN/double-rebase-todo)\n\tset old_labels (rg \"^\\s*(l|label)\\s+([^ \\t#]+)\" -or '$2' $MAIN/git-rebase-todo)\n\tset fresh_labels $new_labels\n\n\t# One of the new_labels is already in use, make a new version\n\twhile string match -qr '^('(string join '|' -- $old_labels)')$' -- $fresh_labels\n\t\tset I (math $I + 1)\n\t\tset fresh_labels $new_labels$I\n\tend\n\n\t# Change to the new labels\n\tif test $I -gt 0\n\t\trg '^\\s*(l|label|t|reset)\\s+([^ \\t#]+)' -r '$1 ${2}'$I $MAIN/double-rebase-todo | sponge  $MAIN/double-rebase-todo\n\tend\n\n\t# Go to the <new base>\n\tgit reset --hard $argv[3] || exit\n\n\t# Prepend the new todo list to the existing one\n\tcat $MAIN/double-rebase-todo $MAIN/git-rebase-todo | sponge $MAIN/git-rebase-todo || exit\n\n\t# Bassically act like git rebase -i would, except use the todo list we just constructed\n\tgit rebase --edit-todo && git checkout $argv[2] && git rebase --continue\n\n— Isaac Oscar Gariano​\n\n\n"},{"id":"524361","messageId":"aKOHuOYFbvHpONaN@nubble.lan","threadId":"63981","inReplyTo":"SYBP282MB29631756F18E53B16F2550848C31A@SYBP282MB2963.AUSP282.PROD.OUTLOOK.COM","subject":"Re: [Feature request] allow git rebase while already rebasing","fromName":"Oswald Buddenhagen","fromEmail":"oswald.buddenhagen@gmx.de","sentAt":"2025-08-18T20:06:16Z","receivedAt":"2025-08-18T20:06:18Z","isPatch":false,"sender":{"key":"oswald.buddenhagen@gmx.de","avatar":"https://avatars.githubusercontent.com/u/812380?v=4"},"body":"On Mon, Aug 18, 2025 at 07:29:45PM +0000, Isaac Oscar Gariano wrote:\n>I suggest removing this limitation, basically the idea is that if you do \"git rebase\" while you are already rebasing, it performs the following:\n>* it computes a new todo list as normal, and then prepends it to the current todo list\n>* it does a 'git reset --hard <start point>' like normal\n>\n>If anyone knows of any tools that let you do this, it would be great.\n>\nhttps://lore.kernel.org/git/390e6a25-72db-8a9e-97af-7b9d803cfb2d@gmail.com/T/#u\non top of\nhttps://lore.kernel.org/git/a6e31eb9-81e7-4d7f-28cc-73b5e46525a4@gmail.com/T/#r890ce9ed689422db9fc40d2bc2cba36f7b183ec3\n\n(i'm keeping rebasing this series, but it's still not ready. if you want\nto work on it, i can post the current patches.)\n\n"},{"id":"524363","messageId":"SYBP282MB2963C3EEE09AE697793529AF8C31A@SYBP282MB2963.AUSP282.PROD.OUTLOOK.COM","threadId":"63981","inReplyTo":"aKOHuOYFbvHpONaN@nubble.lan","subject":"Re: [Feature request] allow git rebase while already rebasing","fromName":"Isaac Oscar Gariano","fromEmail":"isaacoscar@live.com.au","sentAt":"2025-08-18T20:46:05Z","receivedAt":"2025-08-18T20:46:08Z","isPatch":false,"sender":{"key":"isaacoscar@live.com.au","avatar":null},"body":"Oh cool, I'll take a look at that!\n\n(Thanks for the quick reply, natural I never though to search \"rewind\").\n\n— Isaac Oscar Gariano​\n\n\n\n— Isaac Oscar Gariano​\n\n\n\n\n________________________________________\nFrom: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>\nSent: Tuesday, 19 August 2025 6:06 AM\nTo: Isaac Oscar Gariano <isaacoscar@live.com.au>\nCc: git@vger.kernel.org <git@vger.kernel.org>\nSubject: Re: [Feature request] allow git rebase while already rebasing\n \nOn Mon, Aug 18, 2025 at 07:29:45PM +0000, Isaac Oscar Gariano wrote:\n>I suggest removing this limitation, basically the idea is that if you do \"git rebase\" while you are already rebasing, it performs the following:\n>* it computes a new todo list as normal, and then prepends it to the current todo list\n>* it does a 'git reset --hard <start point>' like normal\n>\n>If anyone knows of any tools that let you do this, it would be great.\n>\nhttps://lore.kernel.org/git/390e6a25-72db-8a9e-97af-7b9d803cfb2d@gmail.com/T/#u\non top of\nhttps://lore.kernel.org/git/a6e31eb9-81e7-4d7f-28cc-73b5e46525a4@gmail.com/T/#r890ce9ed689422db9fc40d2bc2cba36f7b183ec3\n\n(i'm keeping rebasing this series, but it's still not ready. if you want\nto work on it, i can post the current patches.)\n"}]}