协慌网

登录 贡献 社区

Git:无法检出分支 - 错误:pathspec'...' 与 git 已知的任何文件都不匹配

我不确定为什么我无法检出我以前处理过的分支。请参阅以下命令(注意: co checkout的别名):

ramon@ramon-desktop:~/source/unstilted$ git branch -a
* develop
  feature/datts_right
  feature/user_controlled_menu
  feature/user_controlled_site_layouts
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/feature/datts_right
  remotes/origin/master
ramon@ramon-desktop:~/source/unstilted$ git co feature/user_controlled_site_layouts 
error: pathspec 'feature/user_controlled_site_layouts' did not match any file(s) known to git.

我不确定这是什么意思,而且我似乎无法在 Google 上找到任何我能理解的东西。

我如何结帐该分支,我该怎么做才能打破这一分支?

更新

我找到了这篇文章,并运行git show-ref给我:

97e2cb33914e763ff92bbe38531d3fd02408da46 refs/heads/develop
c438c439c66da3f2356d2449505c073549b221c1 refs/heads/feature/datts_right
11a90dae8897ceed318700b9af3019f4b4dceb1e refs/heads/feature/user_controlled_menu
c889b37a5ee690986935c9c74b71999e2cf3c6d7 refs/heads/master
c889b37a5ee690986935c9c74b71999e2cf3c6d7 refs/remotes/origin/HEAD
e7c17eb40610505eea4e6687e4572191216ad4c6 refs/remotes/origin/develop
c438c439c66da3f2356d2449505c073549b221c1 refs/remotes/origin/feature/datts_right
c889b37a5ee690986935c9c74b71999e2cf3c6d7 refs/remotes/origin/master
23768aa5425cbf29d10ff24274adad42d90d15cc refs/stash
e572cf91e95da03f04a5e51820f58a7306ce01de refs/tags/menu_shows_published_only
429ebaa895d9d41d835a34da72676caa75902e3d refs/tags/slow_dev

.git目录的更新user_controlled_site_layoutsrefs/heads/feature folder ):

$ ls .git/refs/heads/feature/
datts_right  user_controlled_menu  user_controlled_site_layouts
$ cat .git/refs/heads/feature/user_controlled_site_layouts
3af84fcf1508c44013844dcd0998a14e61455034

git show 3af84fcf1508c44013844dcd0998a14e61455034更新

$ git show 3af84fcf1508c44013844dcd0998a14e61455034
commit 3af84fcf1508c44013844dcd0998a14e61455034
Author: Ramon Tayag <[email protected]>
Date:   Thu May 12 19:00:03 2011 +0800

    Removed site layouts migration

diff --git a/db/schema.rb b/db/schema.rb
index 1218fc8..2040b9f 100755
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended to check this file into your version control system.

-ActiveRecord::Schema.define(:version => 20110511012647) do
+ActiveRecord::Schema.define(:version => 20110503040056) do

   create_table "attachments", :force => true do |t|
     t.string   "name"
@@ -205,15 +205,6 @@ ActiveRecord::Schema.define(:version => 20110511012647) do
     t.integer  "old_id"
   end

-  create_table "site_layouts", :force => true do |t|
-    t.string   "name"
-    t.text     "description"
-    t.text     "content"
-    t.integer  "site_id"
-    t.datetime "created_at"
-    t.datetime "updated_at"
-  end
-
   create_table "site_styles", :force => true do |t|
     t.text     "published"
     t.datetime "created_at"

答案

尝试git fetch以便您的本地存储库从 github 获取所有新信息。它仅接收有关新分支的信息,而无需实际代码。之后, git checkout应该可以正常工作。

尝试签出新分支时出现此错误:

错误:pathspec“分支名称” 与 git 已知的任何文件都不匹配。

当我尝试git checkout origin/<BRANCH-NAME> ,我得到了分离的 HEAD:

(与来源 / 分离)

最后,我执行了以下操作来解决此问题

git remote update
git fetch 
git checkout --track origin/<BRANCH-NAME>

对于远程且没有本地跟踪分支的分支,我收到此错误。即使我确定我已经通过一个简单的方法签出了远程分支

git checkout feature/foo

在过去,要解决此错误,我不得不

git checkout -t -b feature/foo origin/feature/foo

我也不知道我为使自己陷入那种境地做了什么。