git checkout之一 HEAD基本和detached 状态
http://blog.csdn.net/csfreebird/article/details/7583363
1.HEAD基礎
git checkout 實際上是修改HEAD文件的內容,讓其指向不同的branch。
HEAD文件指向的branch就是當前branch.
一般來講,HEAD的內容是指向staging(暫存區)的master文件的。
[plain]?view plaincopyprint?
通過git branch命令看到的結果和HEAD文件內容一致。
[plain]?view plaincopyprint?
2.最簡單用法
git checkout最簡單的用法,顯示工作區,暫存區和HEAD的差異:
[plain]?view plaincopyprint?
如果用-a 參數,可以看到很多branch,包括遠程的branch,比如:
[plain]?view plaincopyprint?
3.detached HEAD
如果讓HEAD文件指向一個commit id,那就變成了detached HEAD。git checkout 可以達到這個效果,用下面的命令:
[plain]?view plaincopyprint?
下面演示如何進入datached HEAD狀態,并恢復回來。
[plain]?view plaincopyprint?
[plain]?view plaincopyprint?
我并不清楚detached HEAD有何實際用處,反正就是一個讓HEAD隨便指向某個commit id,而不在乎是哪個branch的功能。
http://stackoverflow.com/questions/10228760/fix-a-git-detached-head
Detached head means you are no longer on a branch, you have checked out a single commit in the history (in this case the commit previous to HEAD, i.e. HEAD^).
You only need to checkout the branch you were on, e.g.
git checkout masterNext time you have changed a file and want to restore it to the state it is in the index, don't delete the file first, just do
git checkout -- path/to/fooThis will restore the file foo to the state it is in the index.
總結
以上是生活随笔為你收集整理的git checkout之一 HEAD基本和detached 状态的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Struts2拦截器实现异常处理机制
- 下一篇: Windows平台下安装Hadoop