はじめに

[git submodule add]コマンドを実行したときにエラー「A git directory for ‘[指定モジュール]‘ is found locally with remote(s):」が出たので解決案をメモします。

エラー発生から解決まで

こちら環境ではvolleyというandroidの通信ライブラリを導入時にエラーがでました。
フローとしては、最初の一回目のsubmodule化ではエラーにはなりません。一度入れたsubmoduleを削除するときに、[rm -rf]で単に削除し、再度[git submodule add]を行おうとするとエラーになります。
[git submodule add]で追加してgit上削除できていないものがあることでエラーが発生しています。

エラー内容:

A git directory for ‘lib/volley’ is found locally with remote(s):
origin https://android.googlesource.com/platform/frameworks/volley
If you want to reuse this local git directory instead of cloning again from

https://android.googlesource.com/platform/frameworks/volley

use the ‘–force’ option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the ‘–name’ option.

解決方法

不要な設定情報とファイルを手動で削除することで解決します
以下の3手順を全て実行してください

  • .gitmodulesファイルから追加したモジュール情報を削除する
  • .git/configファイルのモジュール情報を削除する
  • .git/modules/配下にあるsubmodule化したリポジトリを削除する

ここまでで、再度[git submodule add]ができるようになりました

正しいsubmodule化したリポジトリの削除方法

そもそも削除の方法が悪かったようです。以下の方法で削除すれば上記のようなエラーにはならないはずです。

引用:

submoduleの削除

gitのバージョンが1.8.5以上なら以下の方法で出来る。
$ git submodule deinit <消したいsubmoduleへのパス>
$ git rm <消したいsubmoduleへのパス>

http://qiita.com/tanishi/items/95463a71c0cdfcece185

その他おすすめの備忘録

Tagged with:
 

コメントを残す