日頃の習慣としてGitの操作でAddしてCommitする前にはgit status
でどのファイルが変更されたことになっているか確認しておいたほうが良いものです。
$ git status
On branch aaa-bbb-branch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: docker-compose.yml
modified: frontend/src/bbb.tsx
Untracked files:
(use "git add <file>..." to include in what will be committed)
node/
frontend/src/aaa.tsx
git status
コマンドに特にオプションをつけないと上記のような表示になります。この時、新規に作成したディレクトリのnode/
は展開されていません。実はこのディレクトリはNode.jsのサーバー一式で、Git管理下に置きたくないnode_modules/
ディレクトリが存在するのですが.gitignore
に追加し忘れている状態です。こういったGit管理下に置きたくないものの存在をgit status
コマンドで確認するためには-uall
をつけます。-uall
をつけるとディレクトリが展開されて表示されます。
$ git status -uall
On branch aaa-bbb-branch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: docker-compose.yml
modified: frontend/src/bbb.tsx
Untracked files:
(use "git add <file>..." to include in what will be committed)
node/.gitignore
node/Dockerfile
node/node_modules/.bin/mime
node/node_modules/.package-lock.json
...略
このようにgit status -uall
であればUntracked filesなディレクトリの中のファイルも表示されるのでうっかり不要なファイルのCommitや.gitignore
の設定ミスに気が付けるでしょう。