如果我这样做git checkout HEAD^,我得到这个:
$ git checkout HEAD^
Note: checking out 'HEAD^'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at...
$
Run Code Online (Sandbox Code Playgroud)
经验丰富的git用户可能对此非常熟悉.但如果我这样做git checkout HEAD,没有任何反应:
$ git checkout HEAD
$
Run Code Online (Sandbox Code Playgroud)
我想在我当前分支的头部为提交创建"分离的HEAD"状态.我怎么做?
Von*_*onC 37
实际上,从git 1.7.5(2011年4月)开始,您可以使用该git checkout --detach命令.
请参阅提交326696
checkout:介绍--detach" git checkout foo^{commit}"的同义词例如,在进行临时合并时可以使用此方法来测试两个主题是否可以很好地协同工作.
提交8ced1aa(git 1.7.11.3,2012年7月)不允许--detach在未出生的分支上,所以这不会在null上失败HEAD:
git checkout --orphan foo
git checkout --detach
git symbolic-ref HEAD
Run Code Online (Sandbox Code Playgroud)
只有upcomming git 1.8.4.2或1.8.5(2013年第4季度)才能澄清语法.请参阅commit 26776c9:
将此案例分为两种语法形式,模仿描述部分显示此用法的方式.
还要更新解释语法的文本,以便将要分离的提交命名HEAD为澄清.
'git checkout' [--detach] <commit>::
Run Code Online (Sandbox Code Playgroud)
准备工作
<commit>,通过HEAD在其上分离(参见"DETACHED HEAD"部分),并更新索引和树将是提交中记录的状态加上本地修改.
当
<commit>参数是分支名称时,该--detach选项可用于HEAD在分支的末端分离(git checkout <branch>将检查该分支而不分离HEAD).省略当前分支顶端的
<branch>分离HEAD.
最后一点正是您想要为当前分支做的事情:
git checkout --detach
Run Code Online (Sandbox Code Playgroud)
pla*_*rms 10
此命令从任何给定的分支名称(在本例中为master)创建一个分离的头状态:
git checkout master^0
Run Code Online (Sandbox Code Playgroud)
它也适用于提交哈希:
git checkout 823112f444cb4aa70032feea6e8e5eb79d0e1ed0
Run Code Online (Sandbox Code Playgroud)
当然还有较短的哈希值:
git checkout 823112f
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16048 次 |
| 最近记录: |