LoginSignup
42
29

More than 3 years have passed since last update.

git add .で警告。warning: adding embedded git repository:

Posted at

警告内容

$ git add .
warning: adding embedded git repository: リポジトリ名
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint:     git submodule add <url> リポジトリ名
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:     git rm --cached リポジトリ名
hint: 
hint: See "git help submodule" for more information.

ー 原因は? ー

コミットしようとしたプロジェクトのフォルダの中に、別に取り込んできたリポジトリがあるからステージングできない

思い当たることと言えば、確かにcloneしたリポジトリへ別のリポジトリのものを取り込んできていました。
原因はそこでしたね。

そして、解決策は?

試したこと

hint:     git rm --cached リポジトリ名

で記載されている通りに$ git rm --cached リポジトリ名
してみましたが、

error: the following file has staged content different from both the
file and the HEAD:

とのことで、『違うファイルがステージングされる』から無理ですよ。ってことですかね。

解決法

そこで一度/.gitをを削除します。

$ rm -rf リポジトリ名/.git

これで、$ git add .は問題なくパスできます。

しかし、続いてはコミット&プッシュができない。

そこで今度は以下のコマンドを打ちました。

$ mv リポジトリ名 subfolder_tmp
$ git submodule deinit リポジトリ名
$ git rm --cached リポジトリ名
$ mv subfolder_tmp リポジトリ名
$ git add リポジトリ名

解決しました。

42
29
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
42
29