Create branch from current working tree and reset to HEAD

我的未来我决定 提交于 2019-12-09 14:23:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!