2012-08-03 23 views

回答

137

如果你還記得哪些分公司之前簽出(如master)你可以簡單地

git checkout master 

走出分離的頭狀態。

一般來說:git checkout <branchname>會讓你失望。

如果你不記得最後一個分支的名稱,儘量

git checkout - 

這也嘗試看看你的最後簽出的分支。

13

使用git reflog來查找以前簽出的提交的哈希值。

的快捷命令到你最後檢出分支(不知道這工作與分離的頭和中間正確提交雖然)是git checkout -

0

我有這個優勢的情況下,在這裏我檢查了代碼的先前版本中,我的文件目錄結構是不同的:

git checkout 1.87.1          
warning: unable to unlink web/sites/default/default.settings.php: Permission denied 
... other warnings ... 
Note: checking out '1.87.1'. 

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 50a7153d7... Merge branch 'hotfix/1.87.1' 

在的情況下,這樣你可能需要使用--force(當你知道回到原來的分支並放棄更改是一件安全的事情)。

git checkout master沒有工作:

$ git checkout master 
error: The following untracked working tree files would be overwritten by checkout: 
web/sites/default/default.settings.php 
... other files ... 

git checkout master --force(或git checkout master -f)工作:

git checkout master -f 
Previous HEAD position was 50a7153d7... Merge branch 'hotfix/1.87.1' 
Switched to branch 'master' 
Your branch is up-to-date with 'origin/master'.