sidyll sidyll - 4 years ago 181
Git Question

Delete Initial Branch Commit

I was working in a branch in a linear situation to master, like so:

a ---> b[master] ---> c ---> d[branch]


However I noticed that
b
had a mistake in its message so I amended it. The problem is that Git duplicated the commit, to preserve the parent of the branch, resulting in this:

a -+-> b'[master]
|
+-> b ---> c ---> d[branch]


In this case
b'
has the correct message and
b
the incorrect (old) one. How can I delete
b
while setting
b'
as
c
's parent?

Answer Source

You should be able to rebase the master back to the branch and delete b. On your branch do git rebase -i master. You should be given a list of commits b, c and d. Delete b from this list which will cause the commit to be removed and b' will be in the history also.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download