Git 创建分离的 HEAD 所在的分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22366034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:52:44  来源:igfitidea点击:

Git create branch where detached HEAD is

gitgit-branchgit-detached-head

提问by octavian

I tried something like this:

我试过这样的事情:

git branch temp

to create a new branch but don'tmove the HEAD. But I get:

创建一个新分支,但不要移动HEAD. 但我得到:

# Not currently on any branch.

I don't want to merge anything, I just want a new branch at the current HEAD.

我不想合并任何东西,我只想在当前HEAD.

回答by redhotvengeance

You're sitting on a detached HEAD:

你坐在一个独立的HEAD

git checkout <sha>

You want to make a branch at that commit:

你想在那个提交上创建一个分支:

git branch my-new-branch

And now switch to that branch:

现在切换到该分支:

git checkout my-new-branch