【git】warning: adding embedded git repository:
リハビリですwwwww
最近はやることが爆発してここ一ヶ月くらいブログを休ませて頂きました。
忙しいを言い訳にしてサボるのもなあ、、
ということで心機一転、
のらりくらり再スタートしたいと思います。
今日はそんな中で少しずつ覚えてきたgitに関する操作です。
間違ってgitリポジトリの中で再度git cloneしてしまった...
ありますよね、僕の場合特定のブランチだけをクローンしようとしたときにそれは起こりました。
この状態でgit add
をすると
❯ git add . warning: adding embedded git repository: app/rails-tutorial 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> app/rails-tutorial hint: hint: If you added this path by mistake, you can remove it from the hint: index with: hint: hint: git rm --cached app/rails-tutorial hint: hint: See "git help submodule" for more information.
このような文章つまり
「プロジェクト内に別で取りこんできたリポジトリがあるため git add できません」
と警告が出ます。
gitのなかにgit ....どうにかしなくては
やったこと
git rm --cached リポジトリ名
こちらでファイルを残したままギットの管理対象から外すことができることのこと
やってみると
❯git rm --cached (リポジトリ) error: the following file has staged content different from both the file and the HEAD: (リポジトリ) (use -f to force removal)
-f をつけて強制的にリムーブしろ、と
❯ git rm -f --cached app/rails-tutorial rm (リポジトリ)
どうやら -f をつけたら強制的にリポジトリ内にできたリポジトリを除去できるようです。
コマンドを整理すると
ファイルを残したまま管理対象外にするコマンド
(--cachedオプションをつけるとファイルを残し、つけないとファイルごと削除される)
git rm --cached [ファイル名]
ファイルごと削除するコマンド
git rm [ファイル名]
らしいです、間違ってファイルをクローンしたときに使えますね!!
おしまい