为什么我无法创建/结帐这个分支? [英] Why am I unable to create/checkout this branch?

查看:97
本文介绍了为什么我无法创建/结帐这个分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个本地Git分支,但它不起作用。
下面是我使用的命令:

  tablet:edit11 $ git checkout  - b edit_11 
切换到新分支'edit_11'
tablet:edit11 $ git checkout edit_11
错误:pathspec'edit_11'与git已知的任何文件都不匹配。
tablet:edit11 $ git branch
tablet:edit11

发生了什么?

解决方案

您成功创建并切换到名为 edit_11 当你跑时

  git checkout -b edit_11 

但是,所有内容(包括一个空的 git分支输出)表示您刚刚初始化了您的存储库并且尚未完成进行初始提交。如果没有提交,分支没有任何用处可以指出,并且没有什么可以检出。



因此,当您运行

  git checkout edit_11 

以下错误:

 错误:pathspec'edit_11'与git已知的任何文件都不匹配。 

尽管分支 edit_11 确实存在。 / p>




问题可以复制如下:

  $ mkdir testgit 
$ cd testgit
$ git init
在/xxxx/testgit/.git/ $ b中初始化为空的Git存储库$ b $ git checkout -b edit_11
切换到新分支'edit_11'
$ git checkout edit_11
错误:pathspec'edit_11'与git已知的任何文件都不匹配。
$ git branch
$

在分支 edit_11 git checkout edit_11 不会再抛出任何错误。请注意,这是一个无操作,因为当前分支已经是 edit_11

  $ printf foo> README 
$ git add README
$ git commit -madd README
[edit_11(root-commit)90fe9c1] add README
1个文件已更改,1个插入(+)
create mode 100644自述文件
$ git分支
* edit_11
$ git checkout edit_11
已在'edit_11'


I am trying to create a local Git branch, but it is not working. Here are the commands I am using:

tablet:edit11$ git checkout -b edit_11
Switched to a new branch 'edit_11'
tablet:edit11$ git checkout edit_11
error: pathspec 'edit_11' did not match any file(s) known to git.
tablet:edit11$ git branch
tablet:edit11$

What's going on?

解决方案

You successfully created and "switched to" a branch called edit_11 when you ran

git checkout -b edit_11

However, everything (incl. an empty git branch output) indicates that you have just initialised your repository and have yet made to make an initial commit. If there is no commit, branches have nothing useful to point at and there is nothing to check out.

Therefore, when you run

git checkout edit_11

you get the following error,

error: pathspec 'edit_11' did not match any file(s) known to git.

even though branch edit_11 does exists.


The problem can be reproduced as follows:

$ mkdir testgit
$ cd testgit
$ git init
Initialized empty Git repository in /xxxx/testgit/.git/
$ git checkout -b edit_11
Switched to a new branch 'edit_11'
$ git checkout edit_11
error: pathspec 'edit_11' did not match any file(s) known to git.
$ git branch
$

After you make a first commit on branch edit_11, git checkout edit_11 will not longer throw any error. Note that this it is a no-op, here, because the current branch is already edit_11.

$ printf foo > README
$ git add README
$ git commit -m "add README"
[edit_11 (root-commit) 90fe9c1] add README
 1 file changed, 1 insertion(+)
 create mode 100644 README
$ git branch
* edit_11
$ git checkout edit_11 
Already on 'edit_11'

这篇关于为什么我无法创建/结帐这个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆