It sounds like what you want to do is a combination of creating a new develop
branch from master
and this answer for How to insert a commit as the first, shifting all the others?.
Let's say you have a history like the following:
$ git --version
git version 1.7.9.rc2.1.g69204
$ git log --oneline --decorate --all
3047e68 (HEAD, master) D
d5b5fdb C
4a26775 B
c53013b A
2a984b8 initial
Create a new develop
branch from the master
branch:
$ git branch develop
$ git log --oneline --decorate --all
3047e68 (HEAD, master, develop) D
d5b5fdb C
4a26775 B
c53013b A
2a984b8 initial
Create a new initial commit and set it up how you like:
$ git symbolic-ref HEAD refs/heads/newroot
$ git rm --cached -r .
$ git add README.md
$ git clean -f -d
$ git commit -m 'new initial'
$ git log --oneline --decorate --all
8b9881c (HEAD, newroot) new initial
3047e68 (master, develop) D
d5b5fdb C
4a26775 B
c53013b A
2a984b8 initial
Now make newroot
the develop
branch and the new initial commit the master
branch:
$ git rebase --onto newroot newroot develop
$ git branch -d newroot
$ git log --oneline --decorate --all
3d589b6 (HEAD, develop) D
f6a83da C
6c8bdc9 B
f8dd99f A
79706b0 initial
8b9881c new initial
3047e68 (master) D
d5b5fdb C
4a26775 B
c53013b A
2a984b8 initial
Now, after you're certain you want to get rid of the existing master
history and make the new initial
commit master
's HEAD
:
$ git reset --hard 8b9881c
HEAD is now at 8b9881c new initial
$ git log --oneline --decorate --all
3d589b6 (develop) D
f6a83da C
6c8bdc9 B
f8dd99f A
79706b0 initial
8b9881c (HEAD, master) new initial
And when the develop
branch is stable and ready for master
:
$ git checkout master
$ git merge --no-ff develop
$ git log --oneline --graph --decorate --all
* e8a5c32 (HEAD, master) Merge branch 'develop'
|\
| * 3d589b6 (develop) D
| * f6a83da C
| * 6c8bdc9 B
| * f8dd99f A
| * 79706b0 initial
|/
* 8b9881c new initial