i hope rob doesn't mind my replying to his personal note from a
while back and CC'ing the list, since there's a bit more here than
meets the eye, and i wanted to make sure i was presenting it fairly.
the problem was, having added, say, 5 linear commits to a branch (A,
B, C, D, E):
... X <-- A <-- B <-- C <-- D <-- E (now HEAD)
i wanted to rebase(?) B through E on top of X as if A never happened.
On Wed, 11 May 2016, Rob Echlin wrote:
> This is why I think Git is the easiest way to shoot yourself in the
> foot, defined here as losing one or more of your commits.
>
> I have only done this in the GUI, but you can choose a commit and
> add the reverse of it to your current state. This means it looks
> sloppy, but I don't care, personally. So you end up with two commits
> you "didn't want", who cares? You still have that commit that
> "today" you don't want. More important, you still have all those
> other commits that you really, really want. Any commit can contain
> information that you can use in other times, other places.
RGB suggested (as i suspected) that one can just rebase "onto", but
i didn't want to just get rid of or revert commit A. rather, in my
case, i realized only after several commits that A had been added to
the wrong branch, so i just wanted to "extract" it from where it was,
and let B through E settle back directly onto X as if A was never
there.
putting A on a different branch was, of course, just a simple
cherry-pick. and while i haven't tested this yet, i'm assuming that i
can use a combination of cherry picking and rebasing to "extract" any
linear sequence of commits from a branch if i decide they properly
belonged elsewhere.
is it just me, or do other people think this is a useful operation?
and is there an even simpler way to do it?
rday
--
========================================================================
Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca
Twitter: http://twitter.com/rpjday
LinkedIn: http://ca.linkedin.com/in/rpjday
========================================================================