| この記事の要点 |
|---|
|
エラーの状況
# ブランチ切替で
$ git checkout feature/login
error: pathspec 'feature/login' did not match any file(s) known to git
# ファイル add で
$ git add my-file.txt
fatal: pathspec 'my-file.txt' did not match any files
# ファイル checkout で
$ git checkout HEAD~1 path/to/file
error: pathspec 'path/to/file' did not match any file(s) known to git
パターン別の原因と対処
パターン 1: ブランチ名のタイポ / リモートのみ存在
# ブランチ一覧確認
$ git branch -a
develop
main
* feature/login
remotes/origin/HEAD -> origin/main
remotes/origin/develop
remotes/origin/feature/auth ← リモートのみ
remotes/origin/feature/login
# ローカルにないがリモートにある場合
$ git fetch origin
$ git checkout feature/auth
# → 自動的に remote から tracking branch 作成
パターン 2: 新規ブランチ作成 (-b 忘れ)
# ダメな例
$ git checkout new-branch
error: pathspec 'new-branch' did not match...
# 修正: 新規ブランチなら -b
$ git checkout -b new-branch
Switched to a new branch 'new-branch'
# Git 2.23+ の新コマンド
$ git switch -c new-branch
パターン 3: ファイルパスの誤り
# 大文字小文字違い
$ git add MyFile.txt
fatal: pathspec 'MyFile.txt' did not match any files
$ ls
myfile.txt ← 小文字
$ git add myfile.txt # 修正
# .gitignore に含まれている
$ cat .gitignore
*.log
build/
$ git add build/output.log
fatal: pathspec...
# → .gitignore に書かれているので追跡対象外
$ git add -f build/output.log # 強制追加 (非推奨)
パターン 4: 未取得のリモートブランチ
# 同僚が push したばかりのブランチ
$ git checkout feature/recently-pushed
error: pathspec...
# リモートを更新してから
$ git fetch origin
$ git checkout feature/recently-pushed
# または
$ git checkout -b feature/recently-pushed origin/feature/recently-pushed
パターン 5: タグやコミット ID
# 古いタグ名のタイポ
$ git checkout v1.0
error: pathspec 'v1.0' did not match...
$ git tag -l
v1.0.0
v1.1.0
v2.0.0
$ git checkout v1.0.0 # 正しいタグ名
パターン 6: detached HEAD 後の操作
# 特定のコミットに移動した状態
$ git checkout abc1234
Note: switching to 'abc1234'.
You are in 'detached HEAD' state.
# そこから新ブランチを切らずにファイル変更
$ git add new-file
fatal: pathspec 'new-file'...
# 解決
$ git switch -c temp-branch
# → これでブランチが切られて add 可能
パターン 7: スパースチェックアウト
# sparse-checkout 有効化中
$ git sparse-checkout init
$ git sparse-checkout set src/
# 範囲外のファイルを操作しようとする
$ git checkout HEAD docs/README.md
error: pathspec 'docs/README.md' did not match...
# 対処: sparse 設定を更新
$ git sparse-checkout add docs/
# または無効化
$ git sparse-checkout disable
調査コマンド
# 管理されているファイル一覧 (HEAD basis)
$ git ls-files
src/main.py
src/util.py
README.md
# 特定の名前で検索 (部分一致)
$ git ls-files | grep -i myfile
# git 管理下にない (untracked) ファイル
$ git status
# ブランチとタグ
$ git branch -a
$ git tag -l
# リモートブランチを最新化
$ git fetch --all --prune
# 履歴を遡って特定ファイルが存在したコミット
$ git log --all --full-history -- "path/to/file"
# 削除されたファイルを探す
$ git log --diff-filter=D --summary | grep delete
未追跡ファイルを git に追加
$ git status
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
new-file.py
$ git add new-file.py
# OK
削除済みファイルを復元
# どのコミットで削除されたか
$ git log --diff-filter=D --summary | grep -A1 "delete mode"
commit abc1234
delete mode 100644 deleted-file.py
# 削除前のバージョンを復元
$ git checkout abc1234^ -- deleted-file.py
$ git add deleted-file.py
$ git commit -m "restore deleted-file.py"
類似エラー
| エラー | 意味 |
|---|---|
pathspec did not match any files | このページ |
did not find any matching ref | ブランチ / タグ参照失敗 |
fatal: not a git repository | git 管理されていないディレクトリ |
You have unstaged changes | 未コミット変更で operation 失敗 |
refusing to merge unrelated histories | 共通祖先がない (--allow-unrelated-histories) |
関連記事
子ページ
子ページはありません
同階層のページ
- fatal: remote origin already exists.
- fatal: '~' does not appear to be a git repository
- Cannot rebase: You have unstaged changes. Please commit or stash them.
- remote: error: denying non-fast-forward refs/heads/master (you should pull first)
- error: pathspec ... did not match any file(s) known to git.
- The following untracked working tree files would be overwritten by checkout
- fatal: Not a valid object name: 'master'.
- Unlink of file 'ファイル名' failed. Should I try again? (y/n)
- Another git process seems to be running in this repository
- error: Your local changes to the following files would be overwritten by checkout:
人気ページ
- 1 Eclipseで「サーバーに追加または除去できるリソースがありません。」の原因と対処法
- 2 tomcat の起動 / 停止ログと catalina.log・catalina.out の違い
- 3 JavaScript で base URL を取得する方法|window.location.origin
- 4 YouTube Data API v3 エラー一覧|403・400・404 の原因と対処
- 5 Laravel エラー一覧|500/Blade/DB 接続/ルーティングの代表エラー
- 6 3Dグラフィックスとは|モデリング/レンダリング/主要ソフトウェア (Blender / Maya)
- 7 Spring Frameworkのアノテーション一覧
- 8 【Spring】@Valueアノテーションとは
- 9 CATALINA_HOME の確認方法 (Linux / Mac)
- 10 【Spring】@Autowiredアノテーションとは
最近更新/作成されたページ
- プロジェクトをTomcatプロジェクトとして認識させる方法 2026-10-07 22:32:50
- MySQLの1366 Incorrect string value|Laravelの文字コード・絵文字エラー 2026-10-07 21:54:03
- curlの証明書ホスト名不一致|旧エラー51・現行60の確認と対処 2026-10-07 21:54:03
- LaravelのMassAssignmentException|fillableの原因と安全な対処 2026-10-07 21:54:03
- Eclipse で Tomcat の起動ログがコンソールに出ない時の確認手順 2026-10-07 21:54:02
- MySQLにおける中央値(Median)の導き方(バージョン8未満) 2026-10-07 13:49:45
- getInputForward 2026-10-07 13:41:15
- JSONから配列に変換 2026-10-07 13:41:15
- ビューから値をモデルに格納しコントローラーで受け取る方法 2026-10-07 13:23:41
- Laravelのテーブル作成と定義変更|マイグレーション・up/down・注意点 2026-10-07 13:23:41
- NumPy 配列に要素を追加する方法 (append / concatenate) 2026-10-07 13:23:41
- MariaDB・MySQLで現在日時を取得する方法|NOW・タイムゾーン・保存型 2026-10-07 13:13:36
- 【django】テンプレートで定数を使用する方法 2026-10-07 13:10:15
- Spring BootにおけるApplication.propertiesの環境依存設定の分割方法 2026-10-07 12:09:35
- Not supported for DML operations【Springエラー】 2026-10-07 11:09:38