git branching - how to make current master a branch and then revert master back to previous version?

自闭症网瘾萝莉.ら 提交于 2019-12-03 08:40:24

you are almost done.

Assume you have made a commit on your development files. Then..

git branch experimental_stuff

git reset --hard HEAD^ (go back one previous commit of your master branch to continue your development)

Assume you have not made a commit on your development files. Then.. you need to save your current changes to a temporary directory

git stash

git checkout -b experimental_stuff (create and change branch to experiental_stuff)

git stash pop (populate the temporary directory into experimental branch)

git checkout master (return back to master, and no need to go back the previous commit this time as you don't have that commit)

Suppose I currently have no branches as such

Just to correct you: You always have at least one branch in Git. Even master is a branch, with the same features as any other branches. And Git doesn't handle a branch named master different than another branch. It is just a convention, that most developers name their main branch "master", but you don't need to. You could even delete your master branch and create branches like development, release etc. For your question itself: The answer of Kit Ho is good.

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