19

What non-interactive Git command(s) achieve the change from Before to After in each case?

1a. Reparenting I

Before:

A---B---C---D

After:

  C'---D'
 /
A---B

1b. Reparenting II

Before:

  C---D
 /
A---B

After:

  C
 /
A---B---D'

1c. Reparenting III

Before:

  C
 /
A---B---D

After:

  C---B'---D'
 /
A
4
  • 1
    Your questions sound like quiz questions ... are you sure you are allowed to simply ask on the internet? Commented Feb 12, 2011 at 23:01
  • 11
    Paul, what class even knows what version control is, let alone put git graph node samples on their tests?
    – ironfroggy
    Commented Feb 12, 2011 at 23:12
  • 1
    Quiz does not necessarily have to be a class ... I don't know, but the question(s) simply have so little context that they really sounded like this. Commented Feb 13, 2011 at 15:06
  • 5
    why is a context necessary in this case? I deliberately broke the problem down in to the very specific operations I was trying to do. Commented Feb 14, 2011 at 1:54

2 Answers 2

20

These all look like applications of git rebase --onto.

1a. Reparenting I

Before:

A---B---C---D

After:

  C'---D'
 /
A---B

Set up branches to label the particular commits and then rebase onto.

  1. git checkout -b ex1a-b B
  2. git checkout -b ex1a-d D
  3. git checkout -b ex1a-a A
  4. git rebase --onto ex1a-a ex1a-b ex1a-d

1b. Reparenting II

Before:

  C---D
 /
A---B

After:

  C
 /
A---B---D'

Creating branches is similar to the above: git rebase --onto ex1b-b ex1b-c ex1b-d.

1c. Reparenting III

Before:

  C
 /
A---B---D

After:

  C---B'---D'
 /
A

Again with the branches, but now just git rebase ex1c-c ex1c-d.

7

It depends on your definition of B', C', and D'.

If you want to move around patches, so that (in the first example) git diff B C == git diff A C', then you want to "rebase" (not "reparent") using git rebase as described by Emil.

If, on the other hand, you want to move around snapshots, then you really do want to "reparent". To do this, I suggest using git reparent.

Most likely, you actually want to rebase and not reparent, but for reference, here are the commands for reparenting. They are somewhat complicated, because this is not a normal thing to do.

(The following assumes you are currently in a branch at D.)

1a. Reparenting I

git rebase -i B
# Select the "edit" command for C
git reparent -p A
git rebase --continue

1b. Reparenting II

git reparent -p B

1c. Reparenting III

git rebase -i A
# Select the "edit" command for B
git reparent -p C
git rebase --continue

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.