LoginSignup
2
1

More than 1 year has passed since last update.

【NestJS】「git add .」実行時に「error: 'nest-retrospective/' does not have a commit checked out fatal: adding files failed」というエラーが発生した時の対処法

Last updated at Posted at 2021-10-12

エラー発生時の状況

  • モノレポ方式でGit管理
  • ディレクトリの階層構造
    • nestjs_example
      • nest-retrospective
  • nestjs_exampleディレクトリにいる状態で、nest newnest-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 プロジェクト名

参考サイト

2
1
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
2
1