`
Night舞夜
  • 浏览: 42951 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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

    博客分类:
  • git
阅读更多
以下是发生的场景
在一个空的目录中(/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'
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics