hudac
hudac

Reputation: 2796

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

Upvotes: 3

Views: 68

Answers (1)

VonC
VonC

Reputation: 1323115

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.

Upvotes: 3

Related Questions