LoginSignup
miky-no6
@miky-no6 (大竹 孝典)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Git コマンドプロンプト

Q&A

Git のコマンドプロンプトでステージングしたいのですが $ git add index.md no.2
fatal: pathspec 'index.md' did not match any files
こういうコメントがでます。
どうしたらいいでしょうか?

0

2Answer

当たり前ですがカレントディレクトリにその名前のファイルがなければステージも何もありません.
簡単な英語くらいは解釈できてもいいと思います.あるいはもっと背景情報を補足するべきかと.

2

Comments

  1. ls とうって、そこにファイルがなければ、git add fileでステージングできないです!
    相対パスとかの概念を勉強するといいと思います!!

  2. 生兵法は大怪我のもとですので、gitを基礎から学ぶことをおすすめします。

  3. @miky-no6

    Questioner

    ありがとうございました。

fatal pathspec 'index.md' did not match any files

直訳すれば
「致命的なパス指定 'index.md' はどのファイルにマッチしませんでした。」です。

つまり、git add実行時に
「index.md」が存在しないか、見つけられなかったということを示しています。

どんな時に出るかコメントをつけた一例を以下に提示します。
 補足1:書いてあるコマンド等が分からなければ試しに調べてみてください
 補足2:私の環境は日本語化してあるので一部メッセージが違うかと思います
 補足3:私の環境で実行したためPC名等、一部ぼかしてあります
 補足4:読みやすいようにQiita上で整形しています

# ホームディレクトリ/temp/git_test/内のファイル、ディレクトリの情報を一覧表示
# 補足「ll」 => 「ls」コマンドの「-l」オプション付き「ls -l」の「alias(エイリアス)」
testPC:~/temp/git_test$ ll
合計 8
# 現状は空
drwxr-xr-x  2 test test 4096  7月 10 23:28 ./
drwxr-xr-x 13 test test 4096  7月 10 23:28 ../

# 「git init」で初期化する
testPC:~/temp/git_test$ git init
Initialized empty Git repository in ~/temp/git_test/.git/

# もう一度確認
testPC:~/temp/git_test$ ll
合計 12
drwxr-xr-x  3 test test 4096  7月 10 23:31 ./
drwxr-xr-x 13 test test 4096  7月 10 23:28 ../
# 「git init」コマンドにより作成された
drwxr-xr-x  7 test test 4096  7月 10 23:31 .git/

# ここで存在しないファイルをステージングしようとしてみる
testPC:~/temp/git_test$ git add index.md
# 質問に記載と同様のエラーが表示される
fatal: pathspec 'index.md' did not match any files

# 「git status」を確認する/もちろん何も変更が存在しない
testPC:~/temp/git_test$ git status
ブランチ main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

# 新規に「index.md」というファイルを作成する
testPC:~/temp/git_test$ touch index.md

# もう一度「git status」を確認する
testPC:~/temp/git_test$ git status
# ここでやっと追跡されていないファイルをするように促される
ブランチ main

No commits yet

追跡されていないファイル:
  (use "git add <file>..." to include in what will be committed)
        index.md

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

# 上記指示に従いステージングする
testPC:~/temp/git_test$ git add index.md

# 今度は「fatal: pathspec 'index.md'~」が表示されない(恐らくステージングされた)
testPC:~/temp/git_test$

# ステージングされたか、もう一度「git status」を確認する
# (今度はコミット予定が表示される)
testPC:~/temp/git_test$ git status
ブランチ main

No commits yet

コミット予定の変更点:
  (use "git rm --cached <file>..." to unstage)
        new file:   index.md

もし、上記の流れでGitについて詰まりそうだったら
以下のサイトでの学習をお勧めします。
(学習時、過去に自分がお世話になったので紹介します)

1

Comments

  1. @miky-no6

    Questioner

    ありがとうございました。

  2. 問題が解決したのあれば、質問をクローズしませんか?

Your answer might help someone💌