3

Simply, I've done like this :

A------B-------C
        \
         \
          B2

Now, I want to change B to B2.

A------B2-------C

Is it possible?

SOLUTION HISTORY:

I just added my work history.

$ git log
commit b671c70b C
commit f4acdc2b B
commit 56f38939 A

$ git checkout f4acdc2b 

and I modified something... then committed with -amend option.

$ git commit -amend
$ git log
commit e2fd729 B'
commit 56f3893 A

Now, It became like this:

A------B-------C
        \
         \
          B'

To rebasing B to B'

$ git checkout b671c70b
$ git rebase -i 56f38939

which opens the interactive editor

pick f4acdc2b B
pick 56f38939 A

just remove line pick f4acdc2b, save and quit.

If there is error error: could not apply b671c70b... C, edit all merge conflicts and then,

$ git add .
$ git rebase --continue

$ git log
commit 914c6bc C'
commit 56f3893 A

$ git checkout 914c6bc
$ git rebase e2fd729 
$ git log
commit 5c65190 C''
commit e2fd729 B'
commit 56f3893 A

Now, It looks like this.

A------B'-------C''
JK Park
  • 107
  • 8

2 Answers2

3

To completely remove B you must re-integrate B2 on A and C on B2.

git checkout C
git rebase B2

This rebases branch C on top of B2

A-------B------B2-------C'

(note that C' is a new commit)

But now you still have the B commit in the history. You can remove it with an interactive rebase.

git rebase -i A

which opens the interactive editor

pick 05c98ef B
pick e31d9f0 B2
pick 5d30d05 C

just remove line pick 05c98ef B, save and quit. After this B is removed and your history looks like this

A------B2'-------C''
René Link
  • 48,224
  • 13
  • 108
  • 140
2

You could interactively rebase your branch on top of B2 (on top of A actually, since you want B2 gone):

 git checkout yourBranch # which references C)
 git rebase -i A
 # drop B

That would give:

 A------B2'-------C'

(note that C' is C with a different SHA1, since its parent has changed)
(Same comment for B2, since its parent also changed)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • But in this case `B` will remain in the history. The resulting repository will look like `A-------B------B2-------C'`, doesn't it? – René Link Nov 27 '14 at 08:32
  • @RenéLink True: I have edited the answer to add the interactive part of the rebase – VonC Nov 27 '14 at 08:38