Git:无法签出分支 - 错误:pathspec '...' 与 git 已知的任何文件都不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5989592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: cannot checkout branch - error: pathspec '...' did not match any file(s) known to git
提问by Ramon Tayag
I'm not sure why I'm unable to checkouta branch that I had worked on earlier. See the commands below (note: co
is an alias for checkout
):
我不确定为什么我无法结帐我之前工作过的分支。请参阅以下命令(注意: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.
I'm not sure what it means, and I can't seem to find anything I can understand on Google.
我不确定这意味着什么,而且我似乎无法在 Google 上找到任何我能理解的内容。
How do I checkout that branch, and what may I have done to break this?
我如何结帐该分支,我可以做些什么来破坏它?
UPDATE:
更新:
I found this post, and running git show-ref
gives me:
我找到了这篇文章,跑步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
UPDATE on .git
directory(user_controlled_site_layouts
is in the refs/heads/feature folder
):
更新.git
目录(user_controlled_site_layouts
在 中refs/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
UPDATE on git show 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"
回答by MarkoHiel
Try git fetch
so that your local repository gets all the new info from github. It just takes the information about new branches and no actual code. After that the git checkout
should work fine.
尝试git fetch
让您的本地存储库从 github 获取所有新信息。它只需要有关新分支的信息,而没有实际代码。之后git checkout
应该可以正常工作。
回答by Mayank
I was getting this error when I tried to checkout new branch:
当我尝试结帐新分支时出现此错误:
error: pathspec 'BRANCH-NAME' did not match any file(s) known to git.
错误:pathspec 'BRANCH-NAME' 与 git 已知的任何文件都不匹配。
When I tried git checkout origin/<BRANCH-NAME>
, I got the detached HEAD:
当我尝试时git checkout origin/<BRANCH-NAME>
,我得到了分离的 HEAD:
(detached from origin/)
(脱离原点/)
Finally, I did the following to resolve the issue:
最后,我做了以下事情来解决这个问题:
git remote update
git fetch
git checkout --track origin/<BRANCH-NAME>
回答by Gregory McIntyre
I got this error for a branch that was remote and had no local tracking branch. Even though I'm certain I've checked out remote branches via a simple
对于远程且没有本地跟踪分支的分支,我收到此错误。即使我确定我已经通过一个简单的检查了远程分支
git checkout feature/foo
in the past, to get around this error I had to
过去,为了解决这个错误,我不得不
git checkout -t -b feature/foo origin/feature/foo
I have no idea what I did to get myself into that situation either.
我也不知道我做了什么让自己陷入那种境地。
回答by Francisco Alvarez
If you deleted a branch with git branch -D yourbranchname
and pulled/cloned again your repo, you may need to create your local branch again.
如果您删除了一个分支git branch -D yourbranchname
并再次拉/克隆了您的存储库,您可能需要再次创建您的本地分支。
Try:
尝试:
git checkout -b yourbranchname
回答by bearzyj
I have the same questions, and got some information from this link: git fetch doesn't fetch all branches
我有同样的问题,并从这个链接得到了一些信息:git fetch 不会获取所有分支
So now, I may not sure how this situation happened, at least we can solve it:
所以现在,我可能不确定这种情况是怎么发生的,至少我们可以解决它:
Step 1.Check your "remote.origin.fetch" setting, should be like this
第 1 步。检查您的“remote.origin.fetch”设置,应该是这样的
$ git config --get remote.origin.fetch
+refs/heads/private_dev_branch:refs/remotes/origin/private_dev_branch
$ git config --get remote.origin.fetch
+refs/heads/private_dev_branch:refs/remotes/origin/private_dev_branch
Step 2.Change "remote.origin.fetch" to fetch everything
步骤 2.更改“remote.origin.fetch”以获取所有内容
$ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
$ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
Then, you can try "git pull" (maybe "git fetch origin" also works but I didn't try) to get all the branch.
然后,您可以尝试“git pull”(也许“git fetch origin”也可以,但我没有尝试)来获取所有分支。
回答by StuartLC
Git Windows users beware - without the --icase-pathspecs
or GIT_ICASE_PATHSPECS = 1
env var setting, that git pathspecs will be case-sensitive, in which case
Git Windows 用户要注意 - 如果没有--icase-pathspecs
或GIT_ICASE_PATHSPECS = 1
env var 设置,git pathspecs 将区分大小写,在这种情况下
git checkout origin/FooBranch "Some/Path/To/File.txt"
is not the same as
不一样
git checkout origin/FooBranch "some/path/to/file.Txt"
回答by Sajin M Aboobakkar
If branch name and you dont have any uncommited file, then try this
如果分支名称并且您没有任何未提交的文件,请尝试此操作
git fetch && git checkout <branch name>
回答by Ankit Marothi
I faced the issue while switching my branch.
我在切换分支时遇到了这个问题。
I did a git pull on the current branch and then tried to checkout the new one and it worked
我在当前分支上做了一个 git pull 然后尝试结帐新分支并且它起作用了
git pull // on your old branch
git checkout <new_branch>
git pull // on your old branch
git checkout <new_branch>
回答by OpMt
git pull
That simply fixed it for me :)
那只是为我修复了它:)
回答by Huachao Huang
I got the same problem because I used git clone --depth=1
, which implies --single-branch
.
我遇到了同样的问题,因为我使用了git clone --depth=1
,这意味着--single-branch
.
Do a completed git clone
will fix it.
做一个完成git clone
将修复它。