我不知道为什么我无法检查我之前工作过的分支机构.请参阅以下命令(注意: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.
Run Code Online (Sandbox Code Playgroud)
我不确定这意味着什么,我似乎无法在Google上找到任何我能理解的内容.
如何查看该分支,以及我可以采取哪些措施来解决这个问题?
更新:
我找到了这个帖子,跑步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
Run Code Online (Sandbox Code Playgroud)
.git目录上的UPDATE(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
Run Code Online (Sandbox Code Playgroud)
更新 git show 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"
Run Code Online (Sandbox Code Playgroud)
Mar*_*iel 861
尝试git fetch使您的本地存储库从github获取所有新信息.它只是获取有关新分支的信息而没有实际代码.之后,git checkout应该工作正常.
小智 334
当我试图检查新分支时,我收到此错误:
错误:pathspec'BRANCH-NAME'与git已知的任何文件都不匹配.
当我尝试时git checkout origin/<BRANCH-NAME>,我得到了超然的HEAD:
(与原产地分离/)
最后,我执行了以下操作来解决此问题:
git remote update
git fetch
git checkout --track origin/<BRANCH-NAME>
Run Code Online (Sandbox Code Playgroud)
小智 147
我得到了一个远程分支没有本地跟踪分支的错误.即使我确定我已经通过一个简单的方式检查了远程分支
git checkout feature/foo
Run Code Online (Sandbox Code Playgroud)
在过去,我不得不绕过这个错误
git checkout -t -b feature/foo origin/feature/foo
Run Code Online (Sandbox Code Playgroud)
我也不知道我做了什么让自己陷入这种境地.
Fra*_*rez 86
如果您删除了一个分支git branch -D yourbranchname并再次拉取/克隆了您的仓库,则可能需要再次创建本地分支.
尝试:
git checkout -b yourbranchname
Run Code Online (Sandbox Code Playgroud)
bea*_*zyj 48
我有同样的问题,并从这个链接获得一些信息:git fetch不会获取所有分支
所以现在,我可能不确定这种情况是如何发生的,至少我们可以解决它:
步骤1.检查"remote.origin.fetch"设置,应该是这样的
$ git config --get remote.origin.fetch
+裁判/头/ private_dev_branch:裁判/遥控器/产地/ private_dev_branch
步骤2.更改"remote.origin.fetch"以获取所有内容
$ git config remote.origin.fetch"+ refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
+裁判/头/*:参/遥控器/产地/*
然后,您可以尝试"git pull"(也许"git fetch origin"也可以,但我没有尝试)获得所有分支.
小智 46
只需做一个git fetch origin <branchName>:<branchName>.
这将获取并创建相同的本地副本,因此现在您可以
签入它git checkout <branchName>
Pra*_*mar 34
我的一个分支也遇到了同样的问题。
这些命令对我有用。
git fetch --all
git checkout <branch-name>
Run Code Online (Sandbox Code Playgroud)
Stu*_*tLC 24
Git Windows用户要注意 - 如果没有--icase-pathspecs或者没有GIT_ICASE_PATHSPECS = 1 设置,那git pathspecs将区分大小写,在这种情况下
git checkout origin/FooBranch "Some/Path/To/File.txt"
Run Code Online (Sandbox Code Playgroud)
是不一样的
git checkout origin/FooBranch "some/path/to/file.Txt"
Run Code Online (Sandbox Code Playgroud)
Saj*_*kar 19
如果分支名称并且您没有任何未提交的文件,请尝试此操作
git fetch && git checkout <branch name>
Run Code Online (Sandbox Code Playgroud)
RS1*_*980 16
尝试通过以下方式结帐分支时出现此错误:
git checkout branchX
Run Code Online (Sandbox Code Playgroud)
我以前没有检查过。它仅在明确说明遥控器时才有效:
git checkout --track origin/branchX
Run Code Online (Sandbox Code Playgroud)
这样做的原因是,我在 git config 中配置了 2 个不同的遥控器(origin + sth. else)。由于我不需要第二个遥控器,我将其取下,瞧,它奏效了。通过以下方式设置默认遥控器的替代方法:
checkout.defaultRemote=origin
Run Code Online (Sandbox Code Playgroud)
对我不起作用
Har*_*rsH 14
我通过修改我的 git 配置文件来修复它检查你的 git 目录中的配置文件 - .git\config
它以前有
[remote "origin"]
url = http://git.xyz.com/abc-group/pqr.git
fetch = +refs/heads/develop:refs/remotes/origin/develop
Run Code Online (Sandbox Code Playgroud)
我通过修改它来修复
[remote "origin"]
url = http://git.xyz.com/abc-group/pqr.git
fetch = +refs/heads/*:refs/remotes/origin/*
Run Code Online (Sandbox Code Playgroud)
请注意,头部仅指向一个分支,因此无法找到对其他现有分支的引用,我将其更改为 *,以便检查原点中的所有内容。
Bol*_*ose 13
更好/更简单的一个:
git fetch origin yourLocalBranch:yourLocalBranch
git checkout yourLocalBranch
Run Code Online (Sandbox Code Playgroud)
当我浅克隆一个存储库并得到解决方案时出现此错误例如我要签出的分支是release/120
git ls-remote origin release/120 # make sure the remote branch exits
git fetch origin refs/heads/release/120:refs/remotes/origin/release/120 # fetch to local repo
git co -b release/120 origin/release/120 # checkout to workspace
Run Code Online (Sandbox Code Playgroud)
Som*_*era 12
当我做了以下事情时,我得到了这个:
当我试图检查目录时,我收到此错误.
修理:
我在git扩展中打开了repo.我看到该文件(旧名称)已上演.但由于它不再存在,它无法承诺.
我只是取消了这个文件.
然后我重新将文件(这次正确命名)添加到git并且没有错误地提交.
我今天遇到了这个问题,我试图git checkout foo得到它error: pathspec 'foo' did not match any file(s) known to git.
事实证明我是在错误的回购.所以吸取了教训:在吓坏之前检查一下你正在看哪个回购.
小智 8
首先,结帐父分支.然后键入
git fetch --all --prune
git checkout <your branch>
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!.
小智 8
好吧,我几乎没有像dev/{feature_branch}这样的已删除分支,当我创建一个新分支dev并尝试结帐时,我遇到了同样的问题。我运行了以下命令
git fetch -p
Run Code Online (Sandbox Code Playgroud)
并为我工作。
在Windows操作系统上,默认情况下git与
core.ignorecase = true
Run Code Online (Sandbox Code Playgroud)
这意味着git repo文件将不区分大小写,要更改此项,您需要执行:
\yourLocalRepo> git config core.ignorecase false
Run Code Online (Sandbox Code Playgroud)
你可以在.git\config文件中找到这个配置
我犯了一个愚蠢的错误,在提交时没有提供 -m 标志(笑发生了)
git commit -m "commit message in here"
Run Code Online (Sandbox Code Playgroud)
我url从另一个.git/config文件复制了远程源,因此我的新.git/config文件在本[remote "origin"]节的以下行丢失
fetch = +refs/heads/*:refs/remotes/origin/*
Run Code Online (Sandbox Code Playgroud)
固定以上行 error: pathspec 'master' did not match any file(s) known to git.
我在切换分支机构时遇到了问题。
我在当前分支上做了一个git pull,然后尝试签出新分支,它起作用了
git pull // on your old branch
git checkout <new_branch>
小智 6
三步走
我遇到了同样的问题。. foo当我尝试执行以下操作时,我以为分支已命名:
git checkout foo
Run Code Online (Sandbox Code Playgroud)
我得到:
error: pathspec 'foo' did not match any file(s) known to git.
Run Code Online (Sandbox Code Playgroud)
然后,我尝试使用完整的分支名称:
git checkout feature/foo
Run Code Online (Sandbox Code Playgroud)
然后为我工作。
如果它发生在Windows上,则可能是文件名案例问题.
我今天遇到了这个错误 - 我已经创建了新文件,添加到GIT,然后我将文件名中的一个字母从低到高更改为然后我无法做任何事情 - 提交,还原,从repo删除文件.
我找到的唯一解决方案是再次将文件名更改回完全相同的情况,当我将此文件添加到GIT,然后执行GIT还原以从GIT中删除此文件,然后再次根据需要更改文件名.在那些改变之后,我可以承诺回购,然后推进没有任何问题.
在 Android Studio 中重命名未提交的文件后发生在我身上。
\n\nGit 的存储库中似乎有旧版本,即使它不再存在\xc2\xb4。
\n\nfetch, pull, checkout, add all and so on did not help in my case!\nRun Code Online (Sandbox Code Playgroud)\n\n所以我打开了 TortoiseGit 的 Git GUI,它向我显示了导致问题的确切文件。
\n\n之后我从存储库中删除了该文件
\n\ngit rm -r --cached /path/to/affected/file\nRun Code Online (Sandbox Code Playgroud)\n\n问题就消失了
\n在我的情况下,我有两个分支1)主(用于实时服务器)2)dev(测试服务器).我在各自的服务器上设置了多个远程推送代码.当我试图切换分支时,我得到了错误error: pathspec 'master' did not match any file(s) known to git.
你可以看到它们git remote -v.除了origin遥控器,我已经移除了其他遥控器git remote remove <remote-name>
然后 git fetch
现在我可以通过结帐分支了git checkout <branch-name>.
当我第一次玩git时遇到了同样的问题。尝试我的第一次提交时...
git commit -m 'first commit!'
Run Code Online (Sandbox Code Playgroud)
我收到了OP提到的错误...
error: pathspec 'commit!'' did not match any file(s) known to git.
Run Code Online (Sandbox Code Playgroud)
我以为我可能在提交消息中使用关键字来混淆git,所以我尝试了其他几个字并收到了相同的错误。
最后,我在消息中使用了双引号...
git commit -m "first commit!"
Run Code Online (Sandbox Code Playgroud)
结果证明是成功的...
[master (root commit) 0000000] first commit!
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 dummyDoc.txt
Run Code Online (Sandbox Code Playgroud)
我有一个根本原因
我有一个脚本,该脚本基本上在所有分支中的“ PRJ-1234”中搜索所有与jira issue key相匹配的分支,以在匹配的分支上执行git branch checkout命令
在我的情况下,问题是2个或多个分支共享相同的jira密钥,因此导致我的脚本因上述错误而失败
通过删除旧的未使用的分支并确保只有一个分支的jira键引用已解决该问题
这是我的代码,以防有人要使用它
git remote update
git fetch --all --prune
git branch -r --list *$1* | xargs git checkout --force
Run Code Online (Sandbox Code Playgroud)
另存为 switchbranch.sh
然后从终端使用 ./switchbranch.sh PRJ-1234
最近,当我尝试使用以下命令签出我的主分支时,确实发生了此错误。
git 结账大师
由于 Github 已将命名约定更改为master上述main命令,因此会出现错误。因此,您可以使用以下命令代替。
git checkout main
Run Code Online (Sandbox Code Playgroud)
$ cat .git/refs/heads/feature/user_controlled_site_layouts
3af84fcf1508c44013844dcd0998a14e61455034
Run Code Online (Sandbox Code Playgroud)
您能否确认以下内容有效:
$ git show 3af84fcf1508c44013844dcd0998a14e61455034
Run Code Online (Sandbox Code Playgroud)
可能有人重写了历史并且该提交不再存在(无论出于何种原因)。
| 归档时间: |
|
| 查看次数: |
823522 次 |
| 最近记录: |