pathspec'master 'はgitに知られているどのファイルとも一致しませんでした



Pathspecmasterdid Not Match Any Files Known Git



登場するシーン

ローカルinitウェアハウスを作成してからdevelopブランチを作成し、このブランチでファイル操作を実行してから、commit変更を加えます。

$ git init Initialized empty Git repository in D:/practice/testBranch/.git/ $ git checkout -b develop Switched to a new branch 'develop' $ vim a.txt $ git add a.txt $ git commit -m 'add a new file' [develop (root-commit) f9ac3b8] add a new file 1 file changed, 1 insertion(+) create mode 100644 a.txt

次に、カットしてmasterブランチで、ファイル操作を実行します。この時点で、次のエラーが発生します。



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

問題の原因

コマンドの解決

git initコマンドはデフォルトで1つ作成しますmasterブランチとwill HEAD(現在配置されているローカルブランチへの特別なポインターです)はそのブランチを指します。それでも、合格しますgit branch -aローカルブランチとリモートブランチを見ると、ブランチは表示されません。
git checkout master注文は実際には2つのことを行います。1つは作成することですHEADポイントバックmasterブランチは作業ディレクトリを復元することですmasterポイントされたスナップショットのコンテンツブランチによって。

問題分析

in HEADポイントバックmaster分岐後、作業ディレクトリをmaster分岐が指すコンテンツに復元する必要があります。しかし、最初からdevelopブランチを操作しているので、masterブランチに対応する作業ディレクトリは何にも相当しないため、一致するファイルはありません。



の解き方

リポジトリを初期化する必要があるのは、最初にmasterブランチでいくつかを実行するcommit 1つ追加するなどの操作README.mdファイルなので、実際に1つmasterブランチを作成しました。例えば:

$ git init Reinitialized existing Git repository in D:/practice/testBranch/.git/ $ vim README.md $ git add README.md warning: LF will be replaced by CRLF in README.md. The file will have its original line endings in your working directory. $ git commit -m 'add a new file' [master (root-commit) 0e8c7c3] add a new file 1 file changed, 1 insertion(+) create mode 100644 README.md $ git push Counting objects: 3, done. Writing objects: 100% (3/3), 219 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: Create a pull request for 'master' on GitHub by visiting: remote: https://github.com/benben/testBranch/pull/new/master remote: To github.com:benben/testBranch.git * [new branch] master -> master

進行中push操作すると、プロンプトが表示され、リモートリポジトリに作成できます。masterブランチとローカルmasterブランチがリモートを指しているmasterブランチ。
この時点で合格しますgit branch -aすべてのローカルブランチとリモートブランチを見ることができます。次に、他のブランチを作成して、マスターブランチを切り替えることができます。

$ git branch -a * master remotes/origin/master

ブランチを切り替えるときは、作業ディレクトリ内のファイルが変更されることに注意してください。古いブランチに切り替えると、作業ディレクトリは最後に送信されたときの状態に戻ります。 Gitがこのタスクを正常に実行できない場合、ブランチの切り替えが無効になります。