Deploying a Re-Written Github/Heroku App
I have an app that is live on Heroku/Github, but recently completely rebuilt it from scratch - I want to keep the old repository name, what is the best way 开发者_StackOverflowto replace the live code with the new code?
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.
cd old_version
git rm -rf .
git commit -m "Removing the old code"
git remote add version2 "/path/to/new_version/.git"
git pull version2 master
That should fully preserve both histories and have the new version be the HEAD of orginal repo. I would recommend backing up repos up before you try this.
精彩评论