From: Junio C Hamano <gitster@pobox.com>
To: Michael Lohmann <mial.lohmann@gmail.com>
Cc: phillip.wood123@gmail.com, Johannes.Schindelin@gmx.de,
git@vger.kernel.org, mi.al.lohmann@gmail.com,
phillip.wood@dunelm.org.uk
Subject: Re: [PATCH] rebase-interactive: show revert option and add single letter shortcut
Date: Mon, 18 Dec 2023 10:43:14 -0800 [thread overview]
Message-ID: <xmqqmsu7e4hp.fsf@gitster.g> (raw)
In-Reply-To: <20231218170912.73535-1-mi.al.lohmann@gmail.com> (Michael Lohmann's message of "Mon, 18 Dec 2023 18:09:12 +0100")
Michael Lohmann <mial.lohmann@gmail.com> writes:
> A `revert` in an interactive rebase can be useful, e.g. if a faulty
> commit was pushed to the main branch already, so you can't just drop it.
But wouldn't that be typically done simply by running "git revert",
totally outside the context of "git rebase -i"?
Interactive rebase is more geared toward rearranging an already
built history *after* such a "git revert" is made and possibly other
commits are made either before or after that commit that was created
by "git revert".
And when "git rebase -i" sees such a series of commits, e.g.,
git checkout -b side-branch master
git commit -m "some work"
git commit -m "some more work"
git revert -m "revert a bad one for now" master~4
git commit -m "tentative alternative for what master~4 did"
git rebase -i master
The "revert a bad one for now" commit looks to the machinery just
like any other commit in the todo list.
> When you are already working in a feature branch you might just want to
> revert said commit right where you branched off from main, so you can
> continue working on the feature you intend while still being up-to-date
> otherwise.
Yes, I can see why sometimes you want to work on a history with
effects from certain commits removed. But that does not explain why
you want to _insert_ a revert that you do not even have in the
history anywhere before you start your interactive rebase.
> Another reason why you might not want to drop a commit is if it is a
> work in progress one and you want to properly fix it later, but for now
> need to revert the changes. That way it is a lot cleaner to structure
> your branch like this:
>
> A---B---C (B is WIP commit you cannot use as is)
> =>
> A---B---~B---C (temporarily revert B (called "~B") directly after
> it is created, until you find the time to fix it -
> at which point in time you will naturally drop the
> revert commit)
>
> This way you still have the WIP patch, but "your history is not broken
> the whole time".
A much cleaner way to structure your branch is not to muck with such
tentative changes *on* the branch you eventually want to store the
final result on. Fork another branch and rebase B away:
$ git checkout -b topic-ng topic [*]
$ git rebase -i A
to obtain
A---B---C topic
\
C topic-ng
and then you'd build on top a better version of B eventually
A---B---C
\
C---D---E---...---B*---X
And after that you may "rebase -i" to refine the result, and then
get rid of the tentative work:
$ work work work (still on topic-ng)
...
$ git commit -m "X"
$ git rebase -i A
$ git branch -M topic
Nowhere in the above two flow, there is no need to manually insert a
new "make a revert here of that other commit" in the todo list.
So I am not sure if I buy the above, especially this part:
> +To revert a commit, add a line starting with "revert" followed by the commit
> +name.
It really smells like a confusing odd man out, among all other
existing instructions that are naturally created by the
rebase/sequencer machinery and all the user needs to do is to
shuffle them, never creating a new thing.
[Footnote]
* I do this too frequently that I often do without a separate -ng
branch; once you get used to the flow, you learn to do this kind
of thing on detached HEAD instead, so this step would look more
like
$ git checkout --detach topic
and the remainder of the above procedure will not change. The
last step would become
$ git checkout -B topic
to bring me back to the target branch in a completed form.
One beauty about this "detached HEAD" approach is that output
from "git reflog topic" will show the refinement of the topic as
a single atomic event.
next prev parent reply other threads:[~2023-12-18 18:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-18 6:53 Why is `revert` undocumented in interactive rebase todo help? Michael Lohmann
2023-12-18 10:53 ` Johannes Schindelin
2023-12-18 15:23 ` [PATCH] rebase-interactive: show revert option and add single letter shortcut Michael Lohmann
2023-12-18 16:32 ` Phillip Wood
2023-12-18 17:09 ` Michael Lohmann
2023-12-18 17:26 ` Michael Lohmann
2023-12-18 18:43 ` Junio C Hamano [this message]
2023-12-20 8:53 ` Michael Lohmann
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=xmqqmsu7e4hp.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=mi.al.lohmann@gmail.com \
--cc=mial.lohmann@gmail.com \
--cc=phillip.wood123@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
/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).