All of lore.kernel.org
 help / color / mirror / Atom feed
* [Feature request] allow git rebase while already rebasing
@ 2025-08-18 19:29 Isaac Oscar Gariano
  2025-08-18 20:06 ` Oswald Buddenhagen
  0 siblings, 1 reply; 3+ messages in thread
From: Isaac Oscar Gariano @ 2025-08-18 19:29 UTC (permalink / raw)
  To: git@vger.kernel.org

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.
Now 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".
Unfortunately, if I'm already in the process of a rebase it doesn't work: you can't have nested rebases.

I suggest removing this limitation, basically the idea is that if you do "git rebase" while you are already rebasing, it performs the following:
* it computes a new todo list as normal, and then prepends it to the current todo list
* it does a 'git reset --hard <start point>' like normal

Obviously there needs to be some limitations (e.g. it will probably only work on the merge backend).

If anyone knows of any tools that let you do this, it would be great.
If 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.

In particular, the rest of this email is a fish script which demonstrates that one can actually do this:
	# This will likely not work properly in many cases, it's just a proof of concept
	if test (count $argv) -lt 1
		echo "USAGE: double-rebase <upstream> [<branch> [<new base> <rebase options>...]]"
                echo "which is like \"git rebase <upstream> <branch> --onto <new base> --interactive <rebase options>\"."
                echo "but for when you are already in a rebase"
		exit 1; end

	# Same defaults as git rebase
	if not set -q argv[2]
		set argv[2] HEAD; end
	if not set -q argv[3]
		set argv[3] $argv[1]; end

	set MAIN (git rev-parse --git-path rebase-merge)
	if not test -e $MAIN
		echo "fatal: rebase --merge not in progress"
		exit 1; end

	# Make a backup of the current rebase
	set BACKUP (git rev-parse --git-path rebase-backup)
	if test -e $BACKUP
		echo "fatal: $BACKUP already exists (did a previouse double-rebase crash?)"; end
	mv $MAIN $BACKUP || exit

	# This 'GIT_SEQUENCE_EDITOR' command will print the file to stdout, with 
	# lines starting with a # striped, and then blank the file.
	# Because the file gets blanked, git rebase won't actually do anything
	# to the repo.
	GIT_SEQUENCE_EDITOR="f () { rg -v '^#' \"\$@\"; echo > \"\$@\"; }; f" \
		git rebase -i $argv[4..] --onto=$argv[2] -- $argv[1] $argv[2] > $BACKUP/double-rebase-todo 2>$BACKUP/double-rebase-err

	mv $BACKUP $MAIN || exit

	# If the above rebase print anything to stderr other than an error about the file, being empty, something when wrong
	set -l stat $status
	if not diff -q $MAIN/double-rebase-err (echo "error: nothing to do" | psub)>/dev/null
		cat $MAIN/double-rebase-err >&2
		exit $stat
	end

	# Stupid hack to make the new labels unique
	set new_labels (rg '^\s*(l|label)\s+([^ \t#]+)' -or '$2' $MAIN/double-rebase-todo)
	set old_labels (rg "^\s*(l|label)\s+([^ \t#]+)" -or '$2' $MAIN/git-rebase-todo)
	set fresh_labels $new_labels

	# One of the new_labels is already in use, make a new version
	while string match -qr '^('(string join '|' -- $old_labels)')$' -- $fresh_labels
		set I (math $I + 1)
		set fresh_labels $new_labels$I
	end

	# Change to the new labels
	if test $I -gt 0
		rg '^\s*(l|label|t|reset)\s+([^ \t#]+)' -r '$1 ${2}'$I $MAIN/double-rebase-todo | sponge  $MAIN/double-rebase-todo
	end

	# Go to the <new base>
	git reset --hard $argv[3] || exit

	# Prepend the new todo list to the existing one
	cat $MAIN/double-rebase-todo $MAIN/git-rebase-todo | sponge $MAIN/git-rebase-todo || exit

	# Bassically act like git rebase -i would, except use the todo list we just constructed
	git rebase --edit-todo && git checkout $argv[2] && git rebase --continue

— Isaac Oscar Gariano​



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Feature request] allow git rebase while already rebasing
  2025-08-18 19:29 [Feature request] allow git rebase while already rebasing Isaac Oscar Gariano
@ 2025-08-18 20:06 ` Oswald Buddenhagen
  2025-08-18 20:46   ` Isaac Oscar Gariano
  0 siblings, 1 reply; 3+ messages in thread
From: Oswald Buddenhagen @ 2025-08-18 20:06 UTC (permalink / raw)
  To: Isaac Oscar Gariano; +Cc: git@vger.kernel.org

On Mon, Aug 18, 2025 at 07:29:45PM +0000, Isaac Oscar Gariano wrote:
>I suggest removing this limitation, basically the idea is that if you do "git rebase" while you are already rebasing, it performs the following:
>* it computes a new todo list as normal, and then prepends it to the current todo list
>* it does a 'git reset --hard <start point>' like normal
>
>If anyone knows of any tools that let you do this, it would be great.
>
https://lore.kernel.org/git/390e6a25-72db-8a9e-97af-7b9d803cfb2d@gmail.com/T/#u
on top of
https://lore.kernel.org/git/a6e31eb9-81e7-4d7f-28cc-73b5e46525a4@gmail.com/T/#r890ce9ed689422db9fc40d2bc2cba36f7b183ec3

(i'm keeping rebasing this series, but it's still not ready. if you want
to work on it, i can post the current patches.)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Feature request] allow git rebase while already rebasing
  2025-08-18 20:06 ` Oswald Buddenhagen
@ 2025-08-18 20:46   ` Isaac Oscar Gariano
  0 siblings, 0 replies; 3+ messages in thread
From: Isaac Oscar Gariano @ 2025-08-18 20:46 UTC (permalink / raw)
  To: Oswald Buddenhagen; +Cc: git@vger.kernel.org

Oh cool, I'll take a look at that!

(Thanks for the quick reply, natural I never though to search "rewind").

— Isaac Oscar Gariano​



— Isaac Oscar Gariano​




________________________________________
From: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Sent: Tuesday, 19 August 2025 6:06 AM
To: Isaac Oscar Gariano <isaacoscar@live.com.au>
Cc: git@vger.kernel.org <git@vger.kernel.org>
Subject: Re: [Feature request] allow git rebase while already rebasing
 
On Mon, Aug 18, 2025 at 07:29:45PM +0000, Isaac Oscar Gariano wrote:
>I suggest removing this limitation, basically the idea is that if you do "git rebase" while you are already rebasing, it performs the following:
>* it computes a new todo list as normal, and then prepends it to the current todo list
>* it does a 'git reset --hard <start point>' like normal
>
>If anyone knows of any tools that let you do this, it would be great.
>
https://lore.kernel.org/git/390e6a25-72db-8a9e-97af-7b9d803cfb2d@gmail.com/T/#u
on top of
https://lore.kernel.org/git/a6e31eb9-81e7-4d7f-28cc-73b5e46525a4@gmail.com/T/#r890ce9ed689422db9fc40d2bc2cba36f7b183ec3

(i'm keeping rebasing this series, but it's still not ready. if you want
to work on it, i can post the current patches.)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-18 20:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18 19:29 [Feature request] allow git rebase while already rebasing Isaac Oscar Gariano
2025-08-18 20:06 ` Oswald Buddenhagen
2025-08-18 20:46   ` Isaac Oscar Gariano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.