0

I have a repo where I want to delete all the commits before one commit with the purpose of changing the initial commit of the repo.

I've created a branch with its last commit as the commit I want as the new root:

git checkout -b newroot SHA

Then I've created a new commit for the initial commit:

git checkout -b initial $(echo "Kill history" | git commit-tree $(git write-tree))

Then I want to rebase master on top of initial starting from commit SHA, so I did:

git rebase --onto initial newroot master

But the rebase does not succeed. I get conflicts after applying some commits. Maybe I'm not understanding something but the way I see it, I shouldn't get any conflicts since I just want to apply all the commits of master on top of that new "fake" initial commit.

Thanks in advance.

Henrique Rocha
  • 1,737
  • 1
  • 19
  • 29

1 Answers1

0

You need an orphan

git checkout --orphan newroot master~10
git commit -m 'Kill history'
git cherry-pick master~10..master
git branch -d master

In git, is there a simple way of introducing an unrelated branch to a repository?

Community
  • 1
  • 1
Zombo
  • 1
  • 62
  • 391
  • 407
  • I still get conflicts when doing that, so my initial commands where also correct. I need to figure out why I am getting conflicts, solve them and see what happens. – Henrique Rocha Feb 25 '14 at 17:36