KAIZEN TECH BLOG

「KAIZEN TECH BLOG」は某WEB制作・デジタルマーケティング会社のメンバーが運営する、WEB・デジタル関連の情報発信ブログです。

Gitでクローン時に「Clone succeeded, but checkout failed」が出る時の対処法

こんにちは!丼です。
最近、社用PCをWin7からWin10に切り替えました。

タイトルの件、環境構築していたらハマったのでメモしておきます。

fatal: cannot create directory at 'node_modules/gulp-connect/node_modules/gulp-util/node_modules/dateformat/node_modules/meow/node_modules/normalize-package-data/node_modules/validate-npm-package-license/node_modules/spdx-correct/node_modules/spdx-license-ids': Filename too long
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD' 


Win10でGitのクローンを実行したら怒られました。node_modulesの中のパスが深く、パスの文字数が260文字を超えたために起こる現象ですね。

「そもそもnode_modulesはignoreしようよ」という指摘はごもっともですが、まぁ、色々事情があるんです..笑

対処方法

1. Git Bashでクローンしたファイルが格納されているディレクトリへ移動
2. 以下のコマンドを叩く
git config core.longpaths true
3.コマンドが通ったら続けて以下のコマンドを叩く
git checkout -f HEAD

古いバージョンのnodeをいじっている時は、node_modulesフォルダを削除するたびにパスが長すぎますと怒られていましたが、Windowsはこういうとこ、ちょっと不便ですねぇ。。