Reputation: 1950
I somehow did this:
A -- B -- C (init)
/
Z (master)
I can't figure out how to delete the Z commit or ho to "rebase" it as a parent of A. Is that even possible?
Upvotes: 2
Views: 223
Reputation: 39951
If there is nothing of use in Z you can get rid of it with reset --hard
git reset --hard init (if init is a branch)
or
git reset --hard HEAD^ (moves one commit back)
If you need to keep Z but as early as possible (first possible is after A) then you can do an interactiv rebase
git rebase -i <sha of A>
and reorder de commits as
Z
B
C
(A is not show as it's the root commit)
Upvotes: 2
Reputation: 2763
To make Z commit as the parent of A try this:
git checkout -b b_branch {B hash}
git checkout master
git rebase b_branch
git checkout -b a_branch {A hash}
git rebase master
Upvotes: 1
Reputation: 32458
Why you need to delete it? Just revert that commit.
git revert <SHA-ID>
Or else, You want to nuke commit. The hard reset to HEAD-1
will set your working copy to the state of the commit before your wrong commit.
git reset --hard HEAD~1
Upvotes: 1