LoginSignup
2
2
記事投稿キャンペーン 「2024年!初アウトプットをしよう」

git statusコマンドには git status -uall をつけとくと何かと安全

Posted at

日頃の習慣として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の設定ミスに気が付けるでしょう。

2
2
1

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
2