LoginSignup
52
28

More than 5 years have passed since last update.

git add で fatal: Pathspec '/moge/hoge' is in submodule が出た時の対応

Posted at

現象

gitのリポジトリにディレクトリごと何かを追加した際に、ディレクトリがfileとして認識されてしまっていることがある。

$git status
On branch test_branch
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   .gitmodules
    new file:   moge/hoge  ->hogeは本当はディレクトリ

このまま気づかずにaddしてしまうと、gitにファイルとして認識されてしまう。ディレクトリの中身はindexされない。
無理やりディレクトリの中身をadd しようとすると以下のようなエラーがでてしまう。

$ git add moge/hoge/*
fatal: Pathspec 'moge/hoge/file' is in submodule 'moge/hoge'

解決策

一旦 moge/hogeをgitレポジトリから省いて、再度追加してあげます。
git レポジトリのroot直下で以下実行。

git rm -rf --cached moge/moge/
git add moge/hoge
52
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
52
28