我不确定为什么我不能签出我以前工作过的分支。参见下面的命令(注意: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 fetch --all
git checkout <branch-name>
$ cat .git/refs/heads/feature/user_controlled_site_layouts
3af84fcf1508c44013844dcd0998a14e61455034

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

$ git show 3af84fcf1508c44013844dcd0998a14e61455034

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

我得到这个错误的分支是远程的,没有本地跟踪分支。即使我确定我已经通过简单的检查远程分支

git checkout feature/foo

在过去,为了避免这个错误,我必须

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

我也不知道我做了什么让自己陷入这种境地。

对我来说,是我的证件有问题


在尝试了一些答案后,其中一个帮助我解决了这个问题:

运行git fetch会抛出以下错误:

无法解决主机:bitbucket.org

我所要做的就是强迫我的IDE(在我的情况下是VS Code)记住我的凭据:

git config --global credential.helper wincred

Git立即同步了所有的更改,Git checkout <branche>现在工作正常!

我也遇到了同样的问题(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被定义为一个带有硬编码颜色的别名,我试图在此基础上构建命令