我不确定为什么我不能签出我以前工作过的分支。参见下面的命令(注意: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"

当前回答

如果发生在Windows上,可能是文件名大小写问题。

我今天有这个错误-我创建了一个新文件,添加到GIT,然后我把文件名中的一个字母从下到上更改了,然后我什么都做不了-提交,恢复,从repo删除文件。

我找到的唯一解决方案是再次将文件名更改为与我将该文件添加到GIT时完全相同的情况,然后执行GIT还原以从GIT中删除该文件,然后根据我的需要再次更改文件名。在这些变化之后,我可以承诺回购,然后推送,没有任何问题。

其他回答

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

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

$ git show 3af84fcf1508c44013844dcd0998a14e61455034

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

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

git commit -m "commit message in here"

我有不同的根本原因

我有一个脚本,基本上搜索所有分支中匹配jira问题密钥的“PRJ-1234”的所有分支,在匹配的分支上执行git分支签出命令

在我的情况下,问题是2个或多个分支共享相同的jira密钥,因此导致我的脚本失败与上述错误

通过删除旧的未使用的分支,并确保只有一个分支拥有jira键引用,解决了这个问题

这是我的代码,以防有人想用

git remote update
git fetch --all --prune 
git branch -r --list *$1* | xargs git checkout --force

保存为switchbranch.sh

然后在。/switchbranch.sh PRJ-1234中使用

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 branch -D yourbranchname删除了一个分支,并重新拉/克隆了你的repo,你可能需要重新创建你的本地分支。

试一试:

git checkout -b yourbranchname