2

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?

3 Answers 3

2

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)

Sign up to request clarification or add additional context in comments.

Comments

1

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 

1 Comment

The commit is 'useless' only file in here is empty .gitignore. Commit A has already initialized .gitignore.
1

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

2 Comments

this just ff master ref from Z to the commit C. The commit Z is still in my graph :(
@svobol13 I've updated my post, now it describes how to insert Z commit between B and A

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.