1

I have the following structure:

A-B-C-D (branch-C) \ \ \ H (branch-A) \ \-E-F-G (branch-B) 

I would LIKE this:

A-B-C-D (branch-A and branch-C) \ \ \ \-E-F-G-H (branch-B) 

How do I do this?

2
  • 1
    I've taken the liberty of labeling a couple of branches for you; this will help answers be better. Commented Feb 17, 2012 at 4:52
  • Added branch C to make it even better :) Commented Feb 17, 2012 at 9:21

2 Answers 2

3

Assuming you have branch-B checked out:

git cherry-pick branch-A git push . branch-C:branch-A -f 

You now have the option to delete either branch-A or branch-C - or just keep both.

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

2 Comments

This isn't very useful without branch names - there's a good chance that the OP will end up moving a branch he doesn't want to. Perhaps give names to the branches that start out at G and H?
This will move branch A, and you'll "lose" B-C-D. They'll still be there, but there won't be a branch pointing to them.
1
git checkout branch-B git cherry-pick branch-A # you could also specify H directly 

Now you have H atop G.

git checkout branch-A git reset --hard HEAD^ # you could also specify D directly # HEAD is the current commit; HEAD^ is the previous one 

Now you've removed H from the branch which contained A-B-C-D.

Note that this only has meaning if there's some branch ref pointing to H and G at the start, since a commit object in git incorporates it ancestors; "moving" a commit doesn't mean anything insofar as it changes your branches.

1 Comment

To the OP: replace G and H with the branches that have started out at those commits. (This is what Borealid is getting at with the last paragraph, but I think it's a little clearer this way.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.