当前位置:首页 > 开发 > 开源软件 > 正文

git checkout 报错原因 (error: pathspec 'master' did not match any file(s) known to )

发表于: 2015-03-27   作者:Night舞夜   来源:转载   浏览:
摘要: 以下是发生的场景 在一个空的目录中(/tempRepo) 执行: git init 成功创建一个空的git仓库 注:现在tempRepo上除了.git文件夹外,没有任何文件 然后继续创建并打开一个分支(dev) 执行: git checkout -b dev 现在想checkout 到 master分支 执行: git checkout master
以下是发生的场景
在一个空的目录中(/tempRepo)
执行:
git init
成功创建一个空的git仓库
注:现在tempRepo上除了.git文件夹外,没有任何文件
然后继续创建并打开一个分支(dev)

执行:

git checkout -b dev

现在想checkout 到 master分支
执行:
git checkout master

git checkout -

正常情况下是可以回到master分支的

不过这时是报错误的,错误信息如下:

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

这里是因为,还没有文件被提交过。即没有commit 过任何文件。

当commit过以后就可以切换分支了

备注:此时执行:git branch,只显示有dev 这个branch。

不过我们可以直接再创建一个master出来。

======================================================
下面是整个过程


Tisson@TISSON-0DCB4418 /E/tRepo
$git init
Initialized empty Git repository in e:/tRepo/.git/

Tisson@TISSON-0DCB4418 /E/tRepo (master)
$ ls -ah
.  ..  .git

Tisson@TISSON-0DCB4418 /E/tRepo (master)
$ git checkout -b dev
Switched to a new branch 'dev'

Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.

Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ vim readme.txt

Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ git status
On branch dev

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        readme.txt

nothing added to commit but untracked files present (use "git add" to track

Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ git add .

Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ git status
On branch dev

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   readme.txt


Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ git commit -m "add a new file:readme.txt"
[dev (root-commit) 06e83d0] add a new file:readme.txt
1 file changed, 1 insertion(+)
create mode 100644 readme.txt

Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ git checkout dev
Already on 'dev'

Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.

Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ git checkout -b master
Switched to a new branch 'master'

Tisson@TISSON-0DCB4418 /E/tRepo (master)
$ git checkout master
Already on 'master'

Tisson@TISSON-0DCB4418 /E/tRepo (master)
$ git checkout dev
Switched to branch 'dev'

Tisson@TISSON-0DCB4418 /E/tRepo (dev)
$ git checkout -
Switched to branch 'master'

git checkout 报错原因 (error: pathspec 'master' did not match any file(s) known to )

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
http日志分析工具awstat安装详解(续篇) --AWStats did not find any valid log lines that match
http日志分析工具awstat安装详解(续篇) --AWStats did not find any valid log lines that match
http日志分析工具awstat安装详解(续篇) --AWStats did not find any valid log lines that match
今天在网上下载了一个示例代码,Debug的时候出现了如标题所示的错误,从错误来看是因为该项目代码已
编译别人的工程出现如下错误:Code Sign error: The identity 'iPhone Developer' doesn't match an
报错是因为WIN8中默认的系统账户没有获得超级管理员权限 在win8中如何获得管理员权限步骤: 按WIN+R
cornerstone CheckOut报错解决方法 今天网络超级给力,每秒5M的跑,忽然想再试试SVN能不能使用Corne
exit code 1 1、鼠标右键 -> TortoiseGit -> Settings -> Network 2、SSH client was poin
git did not exit cleanly 我在上传些代码的时候,有时候会遇到“git did not exit cleanly (exit c
Jenkins构建的时候回出现莫名的 Build step 'Archive the artifacts' changed build result to FAIL
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号