エラー発生時の状況
- モノレポ方式でGit管理
- ディレクトリの階層構造
- nestjs_example
- nest-retrospective
- nestjs_example
-
nestjs_exampleディレクトリにいる状態で、nest newでnest-retrospectiveディレクトリを作成後、git.addした時エラー発生
エラーメッセージ
error: 'nest-retrospective/' does not have a commit checked out
fatal: adding files failed
ファイルの詳細を確認 (隠しファイルを含む)
$ cd nest-retrospective/
$ ls -la
total 1280
drwxr-xr-x 15 maiamea staff 480 10 12 07:40 ./
drwxr-xr-x 6 maiamea staff 192 10 12 07:37 ../
-rw-r--r-- 1 maiamea staff 631 10 12 07:37 .eslintrc.js
drwxr-xr-x 9 maiamea staff 288 10 12 07:40 .git/
-rw-r--r-- 1 maiamea staff 391 10 12 07:40 .gitignore
-rw-r--r-- 1 maiamea staff 51 10 12 07:37 .prettierrc
-rw-r--r-- 1 maiamea staff 3339 10 12 07:37 README.md
-rw-r--r-- 1 maiamea staff 64 10 12 07:37 nest-cli.json
drwxr-xr-x 490 maiamea staff 15680 10 12 07:40 node_modules/
-rw-r--r-- 1 maiamea staff 618935 10 12 07:40 package-lock.json
-rw-r--r-- 1 maiamea staff 1974 10 12 07:37 package.json
drwxr-xr-x 7 maiamea staff 224 10 12 07:37 src/
drwxr-xr-x 4 maiamea staff 128 10 12 07:37 test/
-rw-r--r-- 1 maiamea staff 97 10 12 07:37 tsconfig.build.json
-rw-r--r-- 1 maiamea staff 546 10 12 07:37 tsconfig.json
原因
-
nest-retrospectiveに.gitディレクトリがあったことで、別のGitリポジトリとして認識されエラーになった(nestjs_exampleのGitリポジトリの管理対象外とみなされた)
対処法1
-
.gitディレクトリを削除する。
# -r:再帰的に削除 (ディレクトリを削除)
# -f:確認メッセージを表示せずに削除
rm -rf .git
対処法2
-
nest newする時に--skip-gitをつけると、.gitディレクトリは生成されない。
nest new --skip-git プロジェクト名