From: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
To: git@vger.kernel.org
Subject: rewinding interactive rebases
Date: Mon, 21 Feb 2022 20:06:18 +0100 [thread overview]
Message-ID: <YhPiqlM81XCjNWpk@ugly> (raw)
[-- Attachment #1: Type: text/plain, Size: 810 bytes --]
heya,
this post is basically a continuation of
https://public-inbox.org/git/CAE1pOi1XtrWqG7mOdrNt10YoZG0LOAB7i9cc1Gi8oWhULxE57A@mail.gmail.com/
("Is there any way to "interrupt" a rebase?"), but i thought it's
probably better to start a new thread rather than to revive a zombie.
the basic problem is that during significant reworks of (complex)
branches, one will inevitably find oneself in the situation of wanting
to "go back" in the process. fixup commits aren't always optimal, as
subsequent re-ordering may cause conflicts. doing the amend in the right
place to start with cuts away one of the conflict resolutions.
the solution to this is actually rather simple, as demonstrated by the
attached script.
somebody feels like rewriting this as a nice 'git rebase --rewind'
subcommand?
thanks
[-- Attachment #2: git-rebase-rewind --]
[-- Type: text/plain, Size: 942 bytes --]
#! /bin/bash
# Copyright (C) 2022 Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
#
# You may use this file under the terms of the 3-clause BSD license.
gitdir=$(git rev-parse --git-dir) || exit
if ! git diff --quiet HEAD; then
echo "Working directory or index not clean." >&2
exit 1
fi
rbdir=$gitdir/rebase-merge
if ! test -d "$rbdir"; then
echo "No rebase ongoing?" >&2
exit 1
fi
onto=$(<"$rbdir/onto") || exit
todo=$rbdir/git-rebase-todo
git log --reverse --pretty="tformat:pick %h %s" $onto.. > "$todo.new" || exit
(echo "break"; echo; cat "$todo") >> "$todo.new" || exit
mv "$todo" "$todo.old" || exit
mv "$todo.new" "$todo" || exit
if ! git rebase --edit-todo; then
mv "$todo.old" "$todo"
exit 1
fi
if ! test -s "$todo"; then
echo "Empty todo; canceling rewind." >&2
mv "$todo.old" "$todo"
exit 1
fi
rm "$todo.old"
: > "$rbdir/done"
git reset --hard $onto || exit
git rebase --continue || exit
next reply other threads:[~2022-02-21 19:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-21 19:06 Oswald Buddenhagen [this message]
2022-03-01 9:24 ` rewinding interactive rebases Erik Cervin Edin
2022-03-07 16:56 ` Johannes Schindelin
2022-03-07 19:08 ` Oswald Buddenhagen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YhPiqlM81XCjNWpk@ugly \
--to=oswald.buddenhagen@gmx.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).