问题
I currently work on a feature that turns out to be bigger than expected, so it's propably the best to create a branch to work on it. So I need to create a new branch from my current working directory and reset the master branch to the current HEAD so that some fixes to the production environment can be done.
Somehow this sounds like an easy task, yet I can't quite figure it out. Possibly due to my lack of sleep.
回答1:
So, create a working branch:
git checkout -b working_branch
either commit or stash your changes
git add <files>
git commit -m "message"
OR
git stash
Go back to master
git checkout master
git reset HEAD
回答2:
If you haven't yet made a commit then you don't need to move master, it's already at the current HEAD. You can just checkout a new branch with checkout -b, it doesn't need your working tree to be clean.
E.g.
git checkout -b newtopic
You are now on newtopic and can commit your working tree changes here. master doesn't need to move.
来源:https://stackoverflow.com/questions/2089882/create-branch-from-current-working-tree-and-reset-to-head