1

I have to branches, A and B:

1-2-3
  ^ ^
  A B

Say I want to amend commit 2, so I checkout branch A and do git commit --amend. Now my graph looks like this:

1--2'   [A]
 \-2-3  [B]

Is there a way to also automatically update branch B (in case there are no conflicts) so that my graph looks like

1-2'-3
  ^  ^
  A  B

I know that I can do git checkout B && git rebase A and use git rebase --skip, but is there a quicker way?

T-Rex96
  • 355
  • 4
  • 15

1 Answers1

1

That hypothetical expected situation

1-2'-3
  ^  ^
  A  B

cannot happen, since 3 has 2 as its parent forever.

In git, "changing the parent of a commit" is impossible, what you can do is to create a new commit with the new parent (which happens during rebases and cherry-picks, and is often symbolized like your above 2').

Rebasing, as you considered, is the typical way to handle this. (And no, there's no really quicker/easier way.)


A more accurate description of your end result after your rebase :

1---2---3 <<< not referenced anymore, 2 and 3 are candidates for garbage collection
 \
  2' <<< A
   \
    3' <<< B <<< HEAD
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • It would, however, make sense to have a Git command that worked by checkout out commit `3` via branch `B`, then did a rebase that copied `2` to `2'` and `3` to `3'` and then *moved both branch names*. I tried to write this command, but it's *really hard* to get it right for all possible cases. Sometimes you want `A` to move and sometimes you don't. Sometimes there are commits *on* `A` past `2`. And so on... – torek Nov 28 '19 at 23:42
  • I'm not even near the point where writing such a command becomes a possibility, but yes it's what I tried to convey with my vague *there's no really quicker/easier way*. Writing your own commands is not what I would describe as "easy" :-) – Romain Valeri Nov 29 '19 at 00:21