Answers:
我投票赞成将所有内容都保存在一个存储库中。
我会:
这是这样的:
# checkout the master branch
git checkout master
# create a new branch so you can find the old code easily
git branch oldStuff-KeepingForReference
# push the branch to github
git push origin oldStuff-KeepingForReference
# You currently have the master branch checked out
# so now cd to the project root and start your rewrite:
cd <your project root>
rm -rf *
# Create a commit of the delete
git add --all *
git commit -m "Fresh start"
# Start your rewrite
echo "Some changes" > file.txt
git add file.txt
git commit -m "This is the first commit of the rewrite"
另外:如果您永远不会向其添加任何提交,也可以对旧的旧代码进行标记。
当您应该创建一个新的存储库而不是这样做时:
那就是孤立分支的目的。
git branch -m master new_branch #rename the branch
git push origin new_branch:new_branch #push the old code
git push origin :master #delete the origin/master branch containing the old code
git checkout --orphan master #create a new orphane branch - master. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.
echo foo > file.txt
git add file.txt
git commit -m 'init commit'
git push origin master
您可能需要暂时在Github 中将默认分支设置为new_branch
,因为默认情况下它显示为master。