2
0

More than 1 year has passed since last update.

【API開発】git addしたら「error: 'backend/' does not have a commit checked out fatal: adding files failed」となった

Last updated at Posted at 2021-11-20

問題

バックエンドとフロントエンドを分けた開発で、git管理したく、
git add .をしたところ、
error: 'backend/' does not have a commit checked out fatal: adding files failedとなった。

ディレクトリ構成

「backend」と「frontend」のディレクトリ構造にした。

Document
├── backend
├── frontend
├── README.md

原因

.gitファイルが存在しているせいでコミットできなかった。

backend % ls -la
total 56
drwxr-xr-x  21 horitomoyuki  staff   672 11 20 18:04 .
drwxr-xr-x   6 horitomoyuki  staff   192 11 20 18:08 ..
drwxr-xr-x   8 horitomoyuki  staff   256 11 20 19:58 .git
-rw-r--r--   1 horitomoyuki  staff   659 11 20 16:23 .gitignore
-rw-r--r--   1 horitomoyuki  staff     6 11 20 18:04 .ruby-version
-rw-r--r--   1 horitomoyuki  staff  1424 11 20 16:23 Gemfile
-rw-r--r--   1 horitomoyuki  staff  4074 11 20 16:24 Gemfile.lock
-rw-r--r--   1 horitomoyuki  staff   374 11 20 16:23 README.md

解決策

とりあえず、READMEをコミット

echo "# vue-calendar" >> README.md
git init
git add README.md
git commit -m "first commit"
git push -u origin main

続いて、backendとfrontend両方のディレクトリに移動して.gitを消去

rm -rf .git

その後、両ディレクトリでcommit,pushをしたら無事にコミット完了。

参考

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