Move prototype code out of master branch with git
The master branch of a new project's git repo co开发者_JAVA技巧ntains only prototype/spike code. I'm about to re-start the coding from scratch, now that I have the basic ideas understood.
I want the master branch to be clear of all the prototype code. Ideally the prototype code needs to be moved into a branch so I can still get to it later.
Is it possible to reset master back to before the first commit? What are the git commands to do this?
If you're really going to start from scratch, just create a completely new repository. It's possible to have two branches without any common ancestor, but it's not really that useful.
This is how you create a new branch not sharing any history with your other branches: How to create a new empty branch for a new project.
Before following these instructions, just rename your existing master
to prototype
using git branch -m master prototype
. Then, when following the linked instructions, use master
instead of newbranch
.
- From the current
master
branch, make a new branch with your prototype code.git checkout -b prototype
. - Get back to the master branch with
git checkout master
. - Remove all the files from the
master
branch withgit rm -rf *
. - Commit your changes on the
master
branch withgit commit -m "Removed prototype code"
.
This way, the history will be kept and you can always track in the log when the switch took place.
精彩评论