我不确定为什么我不能签出我以前工作过的分支。参见下面的命令(注意:co是签出的别名):

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.

我不知道这是什么意思,我在谷歌上也找不到任何我能理解的东西。

我如何签出该分支,以及我可能做了什么来打破它?

更新:

我找到了这篇文章,运行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_layouts在refs/heads/feature文件夹中):

$ 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更新显示3af84fcf1508c44013844dcd0998a14e61455034

$ git show 3af84fcf1508c44013844dcd0998a14e61455034
commit 3af84fcf1508c44013844dcd0998a14e61455034
Author: Ramon Tayag <xxx@xxxxx.xxx>
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 add includes/connection..php

但我没有注意到我用的是两个点 然后我输入

git add includes/connection.php

它的工作原理

其他回答

最近,当我试图用下面的命令签出到我的主分支时,确实发生了这个错误。

Git checkout master

由于Github已经将命名约定从master更改为main,上面的命令会给你错误。因此,您可以使用下面的命令来代替它。

git checkout main 

在我自己创建的两个本地分支上的Windows上也发生了这种情况。 一出分行,我就不能结帐了

bugfix_ # 303 _multiline_opmerkingen_not_displaying_correctly_in_viewer

也不

bugfix_339_hidden_fields_still_validated

你可以在下面的Git bash截图中看到。

当我尝试使用Git GUI时,我甚至根本无法看到分支。然而,当我使用Pycharms git工具时,我看到了这个:

因此,出于某种原因,窗口决定添加一些难以破译的字符到我的分支名称,这就是它没有工作的原因。在Pycharm中重命名分支达到了目的,所以我猜这也适用于其他ide。

好吧,我有一些删除的分支,如dev/{feature_branch},当我创建一个新的分支dev并试图签出时,我得到了相同的问题。我运行下面的命令

git fetch -p

为我工作。

我今天遇到了这个问题,我试图git签出foo并得到错误:pathspec 'foo'不匹配任何已知的git文件。

事实证明我进错了回购区。因此,我们得到的教训是:在惊慌失措之前,先检查一下你在看哪个回购。

导致此问题的一个可能原因可能是本地存储库与其上游存储库之间也缺乏同步。在这种情况下,简单的git拉入<branch_name>,然后是git签出<branch_name>。