我不确定为什么我不能签出我以前工作过的分支。参见下面的命令(注意: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 Windows用户注意-没有——icase-pathspecs或GIT_ICASE_PATHSPECS = 1 env var设置,Git路径specs将区分大小写,在这种情况下

git checkout origin/FooBranch "Some/Path/To/File.txt"

不一样吗

git checkout origin/FooBranch "some/path/to/file.Txt"

其他回答

尝试git获取,以便您的本地存储库从Github获得所有新信息。它只获取关于新分支的信息,没有实际的代码。之后,git签出应该可以正常工作。

您基本上看到了分支,但还没有本地副本!……

你可以简单地获取然后签出分支,使用下面的命令来完成:

git fetch
git checkout <Branch name here>

我还创建了下面的图像,让你分享它们的区别,看看fetch是如何工作的,以及pull是如何不同的:

我犯了一个愚蠢的错误,在提交时没有提供-m标志(lol发生了)

git commit -m "commit message in here"

只需做一个git获取origin <branchName>:<branchName>。

这将获取并创建一个相同的本地副本,因此现在你可以

checkout到它git checkout <branchName>

我也遇到了同样的问题(git-recent的一个版本),发现这与git使用的颜色转义码有关。我想知道这是否可以解释为什么这个问题如此普遍。

这演示了可能发生的事情,尽管颜色通常是在git配置中设置的,而不是在命令行中设置的(否则它的效果会很明显):

~/dev/trunk (master)$ git checkout `git branch -l  --color=always  | grep django-1.11`
error: pathspec 'django-1.11' did not match any file(s) known to git.
~/dev/trunk (master)$ git branch -l  --color=always  | grep django-1.11
  django-1.11
~/dev/trunk (master)$ git checkout `git branch -l  | grep django-1.11`
Switched to branch 'django-1.11'
Your branch is up-to-date with 'gerrit/django-1.11'.
~/dev/trunk (django-1.11)$ 

我认为git配置不玩颜色设置应该工作color=auto应该做正确的事情。我的特殊问题是,我最近使用的git被定义为一个带有硬编码颜色的别名,我试图在此基础上构建命令

$ cat .git/refs/heads/feature/user_controlled_site_layouts
3af84fcf1508c44013844dcd0998a14e61455034

你能否确认以下工作是否有效:

$ git show 3af84fcf1508c44013844dcd0998a14e61455034

可能是有人重写了历史,这个承诺不再存在了(无论出于什么原因)。