git checkout origin / master不起作用?

时间:2012-08-20 19:23:56

标签: git github git-checkout

我在命令行输入git checkout origin/master,并在第一时间给出以下提示:

Deletion of directory 'dirname1/dirname2' failed. Should I try again? (y/n)

每次尝试都会失败,所以我最终击中了n。然后我明白了:

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 c2850cd... - change description

之后我做git branch,这就是我所看到的:

* (no branch)
  remote/branchname
  master

为什么这样做?如何根据这个提交origin / master?

2 个答案:

答案 0 :(得分:2)

我正在猜测 - 看起来你的工作副本中有一个目录在origin / master中不存在。通常,当您更改分支时,git会删除该目录。但在这种情况下,它不能出于某种原因。可能存在权限问题:该目录可能由其他用户拥有,或者可能是只读的。

尝试删除git抱怨的目录。您可能需要更改其权限或使用sudo。然后你可以使用命令git checkout .将它放回去 - 希望这次具有正确的权限。如果我是对的,那么切换分支应该在那之后工作。

答案 1 :(得分:0)

只有master没有前缀:

git checkout master