1

I have following repository:

* d9da0f2 (HEAD, master) Fifth | * bf3b476 (branch1) branch1 first |/ * 13f93d5 Fourth * 94f2fa1 Third * 5333eb2 Second * be69a71 First 

All I am trying to do is doing something to it to get the following structure:

* d9da0f2 (HEAD, master) Fifth | * bf3b476 (branch1) branch1 first |/ * ?13f93d5? Reworded commit, with all the other commmits squashed/fixuped into it 

I tried following:

git checkout 13f93d5 git rebase -i --root reword be69a71 First fixup 5333eb2 Second fixup 94f2fa1 Third fixup 13f93d5 Fourth 

but ended up with:

* commit a6a091c9bc495b9de5ca51dee5d0032454e669db (HEAD) Author: frigo <frigo@dev> Date: Fri Nov 7 20:18:55 2014 +0100 First reworded * commit d9da0f2f273b91913ac241f3b6b034ef7babf1d1 (master) | Author: frigo <frigo@dev> | Date: Fri Nov 7 20:24:18 2014 +0100 | Fifth | * commit bf3b476491547523321c765857de2097f77cdbd5 (branch1) |/ Author: frigo <frigo@dev> | Date: Fri Nov 7 20:23:54 2014 +0100 | branch1 first * commit 13f93d5ca898a043d37d704d397d34cf1f133a05 | Author: frigo <frigo@dev> | Date: Fri Nov 7 20:20:12 2014 +0100 | Fourth * commit 94f2fa1bb654288860c6af34c0cc9ff1267e0e72 | Author: frigo <frigo@dev> | Date: Fri Nov 7 20:19:57 2014 +0100 | Third * commit 5333eb26b57b038b3b4fdf2cb91590c0254b4024 | Author: frigo <frigo@dev> | Date: Fri Nov 7 20:19:24 2014 +0100 | Second * commit be69a7194413d9760b9f8930edf79afe7095b716 Author: frigo <frigo@dev> Date: Fri Nov 7 20:18:55 2014 +0100 First 

As I expected, the following shows no difference:

git diff 13f93d5 a6a091c 

But still all the commit after the rebased commit remain attached to the old commit hierarchy.

I also tried creating a grafts file with no parent for 13f93d5and running git filter-branch to "carve it into stone", but that still leaves me with the history visible with git --all.

1 Answer 1

1

git checkout aSHA1 means you are in a detached HEAD mode.

You should make your interactive rebase with:

git checkout master git rebase -i --root 

Do the reword and fixup you did, while picking d9da0f2 (the current master HEAd)

Note that will leave branch1 stranded:

# after the rebase: git branch -f branch1 master~1 git checkout branch1 git cherry-pick bf3b476 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Good answer. My problem is that the real repository I try to change has two years worth of history I am trying to get rid of and ca. 15-20 feature branches. Cherry picking all the commits for all the branches is not for the faint hearted(=me). I guess my question was not the best.
@frigo you can cherry-pick a range of commits though (stackoverflow.com/a/1994491/6309: it still would work just fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.