Slight variation from Michael's answer:
git branch -M master old_master
git rm -rf .
git checkout --orphan master
git remote add version2 "/path/to/new_version/.git"
git pull version2 master
(as usual, back up everything first)
If you are using git1.7.2+, you can use git checkout --orphan
:
Similar to -b
, --orphan
creates a new branch, but it starts without any commit.
After running "git checkout --orphan newbranch
", you are on a new branch "newbranch
", and the first commit you create from this state will start a new history without any ancestry.
When creating a branch whose trees have no resemblance to the ones from the original branch, it may be easier to start work on the new branch by untracking and removing all working tree files that came from the original branch, by running a 'git rm -rf .
' immediately after running "checkout --orphan
".
You avoid having two different history on the same branch, with an abrupt change at one specific commit.
Instead you keep several root branches with different history in it.
But that means rewriting the history of commits of master
, which isn't that bad considering you only need the previous history for reference and archive only.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…