hudac hudac - 2 months ago 13
Git Question

Git - how to update an old commit

This is my graph:

Branch A a-->b
|
v
Branch B b-->c


I have branch
B
that came out of branch
A
, from commit
b
.

I did a commit on branch
B
called
c
.

Now let's say I update commit
b
of branch
A
with
git commit --amend
to
b'


Branch A a-->b'
|
v
Branch B b-->c


How do I update comit
b
on branch
B
to be the exact
b'
?

Thanks

Answer

Actually, the grap is

a--b (A)
    \
     c (B)

After amend, you would have a new b' (marking b as tmp):

a--b' (A)
 \
  b--c (B)
(tmp)

You would need to rebase B onto A:

git rebase --onto A tmp B

a--b' (A)
    \
     c' (B)

As divyum comments, you can also merge, but that would add to A, and duplicate b commit between, resulting in possible conflicts:

a--b'--M (A)
 \    /
  b--c (B)

I prefer cherry-picking or rebasing.

Comments