- Git
git statusの見方|Untracked等の意味と-s短縮表示の記号一覧
git status とは、作業中のファイルが「コミット予定」「変更したがまだ予定に入れていない」「Git がまだ追跡していない」のどれに当たるかを一覧で教えてくれるコマンドです。 ファイルの中身は何も書き換えないので、迷ったら何度打っても問題ありません。出力は英語ですが、見出しは実質3種類だけで、それぞれの下に「次に打つコマンド」がヒントとして書かれています。
この記事では、Git 2.43.0 で実際に動かした出力をそのまま貼りながら、3つの見出しの意味と次に打つコマンドの対応表、-s(短縮表示)の2文字記号の一覧、-sb と --porcelain の読み方を整理します。さらに、マージコンフリクト中・rebase 中・ahead / behind・detached HEAD といった「いつもと違う表示」も1つずつ再現して読み方を解説します。英語表示と日本語表示(Ubuntu 24.04 の日本語言語パック)の出力も並べています。
git status の見方 早見表
まず、通常表示(長い形式)に出てくる行と、その意味・次の一手です。
| 表示される行 | 意味 | 次に打つコマンド |
|---|---|---|
On branch main |
いま main ブランチにいる | (確認のみ) |
Your branch is up to date with 'origin/main'. |
最後に fetch した時点のリモートと同じ位置 | 最新か確かめるなら git fetch |
Your branch is ahead of 'origin/main' by 1 commit. |
手元に、まだ push していないコミットが1つある | git push |
Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded. |
リモートに、まだ取り込んでいないコミットが1つある | git pull |
Your branch and 'origin/main' have diverged, |
手元とリモートの両方に別々のコミットがある | git pull --rebase または git pull --no-rebase |
Changes to be committed: |
ステージ済み。次の commit に入る変更 | git commit / 外すなら git restore --staged <file> |
Changes not staged for commit: |
変更したが、まだステージしていない | git add <file> / 変更を捨てるなら git restore <file> |
Untracked files: |
Git がまだ追跡していない新しいファイル | git add <file> / 管理しないなら .gitignore に書く |
Unmerged paths: |
コンフリクト中のファイル | 編集して git add <file> |
nothing to commit, working tree clean |
コミットしていない変更はない | (次の作業へ) |
HEAD detached at 19470b9 |
ブランチではなくコミットを直接見ている | 戻るなら git switch -、残すなら git switch -c <名前> |
短縮表示(git status -s)でよく見る記号は次のとおりです。左の文字がステージ(インデックス)、右の文字が作業ツリーの状態を表します。
| 記号 | 意味 | 通常表示での見出し |
|---|---|---|
M (M+空白) |
変更をステージ済み | Changes to be committed |
M (空白+M) |
変更したが未ステージ | Changes not staged for commit |
MM |
ステージ後にさらに変更した | 両方に出る |
A |
新規ファイルをステージ済み | Changes to be committed |
D |
削除をステージ済み(git rm) |
Changes to be committed |
D |
ファイルを消したが未ステージ | Changes not staged for commit |
R |
名前変更をステージ済み | Changes to be committed |
?? |
追跡されていない | Untracked files |
!! |
無視されている(--ignored 指定時のみ) |
Ignored files |
UU |
両方で変更されコンフリクト中 | Unmerged paths |
本記事の内容は、ご自由にお使いください。
ご利用の際は、出典として本ページへのリンクを記載いただけますようお願いします。
(記載例)出典:株式会社RJC「git statusの見方|Untracked等の意味と-s短縮表示の記号一覧」
git status が見ている3つの場所
git status の出力を読むには、Git がファイルを置く「3つの場所」を知っておくと一気に楽になります。
| 場所 | 役割 | 比べている相手 |
|---|---|---|
| 作業ツリー(working tree) | いま編集しているフォルダそのもの | ステージと比べて差があれば「not staged」 |
| ステージ(インデックス) | 次のコミットに入れる内容の置き場 | 最新コミット(HEAD)と比べて差があれば「to be committed」 |
| リポジトリ(HEAD) | 最後にコミットした内容 | リモート追跡ブランチと比べて ahead / behind |
flowchart LR
U["Untracked files<br>(未追跡)"] -- "git add" --> S
W["Changes not staged for commit<br>(作業ツリーの変更)"] -- "git add" --> S["Changes to be committed<br>(ステージ)"]
S -- "git commit" --> H["HEAD<br>(コミット済み)"]
S -- "git restore --staged" --> W
H -- "git push" --> R["origin/main"]
git status は「作業ツリーとステージの差」「ステージと HEAD の差」「HEAD とリモート追跡ブランチの差」の3つを順に報告している、と覚えておくと、どの表示も同じ型で読めます。
通常表示の読み方|3つの見出しの意味と次に打つコマンド
検証に使った状態
次のコマンドで、3つの見出しが同時に出る状態を作りました(Git 2.43.0、LANG=C.UTF-8)。
git init -q --bare remote.git
git clone -q remote.git work && cd work
printf 'a\n' > app.txt; printf 'r\n' > README.md
git add . && git commit -qm init && git push -q -u origin main
echo b >> app.txt # 変更しただけ(未ステージ)
echo x >> README.md
git add README.md # 変更してステージ
echo new > memo.txt # 新しいファイル(未追跡)
git status
英語表示(実行結果)
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md
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: app.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
memo.txt
日本語表示(実行結果)
同じ状態を、Ubuntu 24.04 の日本語言語パック(language-pack-ja-base)のメッセージカタログを読み込ませ、LANG=ja_JP.UTF-8 で実行した結果です。
ブランチ main
Your branch is up to date with 'origin/main'.
コミット予定の変更点:
(use "git restore --staged <file>..." to unstage)
modified: README.md
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: app.txt
追跡されていないファイル:
(use "git add <file>..." to include in what will be committed)
memo.txt
日本語になる行と英語のままの行が混ざるのがわかります。今回確認した範囲では、Git 2.43.0 のソースに含まれる翻訳チーム一覧(po/TEAMS)に日本語はなく、日本語のメッセージは OS の言語パックなどが個別に用意しているものでした。そのため環境によって訳される範囲が変わります。英語の見出しをそのまま読めるようにしておくと、どの環境でも迷いません。
見出しごとの対応表(英語・日本語・次の一手)
「日本語の意味」の列は、上の実行結果に出た訳(コミット予定の変更点/追跡されていないファイル)と、英語のままだった行を筆者が訳したものです。
| 英語の見出し | 日本語の意味 | どんな状態か | 次に打つコマンド |
|---|---|---|---|
Changes to be committed: |
コミット予定の変更点 | git add 済み。次の git commit に入る |
git commit -m "..." |
| 同上(取り消したい) | 同上 | ステージから外したい | git restore --staged <file> |
Changes not staged for commit: |
コミット予定に入っていない変更 | 追跡中のファイルを編集・削除したが git add していない |
git add <file> |
| 同上(変更を捨てたい) | 同上 | 編集前の内容に戻したい | git restore <file> |
Untracked files: |
追跡されていないファイル | 新しく作ったファイル。Git はまだ履歴に入れていない | git add <file> |
| 同上(管理しない) | 同上 | ログや一時ファイルなど | .gitignore に追記 |
各ファイルの左に付くラベルの意味は次のとおりです。
| ラベル | 意味 | 出る見出し |
|---|---|---|
new file: |
新規ファイルをステージした | Changes to be committed |
modified: |
内容を変更した | to be committed / not staged の両方 |
deleted: |
ファイルを削除した | to be committed / not staged の両方 |
renamed: |
名前を変更した(旧名 -> 新名) |
Changes to be committed |
both modified: |
両方のブランチで変更されコンフリクト中 | Unmerged paths |
かっこ内のヒントは「次のコマンド」そのもの
見出しのすぐ下にある (use "git ..." to ...) は、Git が出してくれる操作の案内です。
| ヒント | 訳 |
|---|---|
(use "git restore --staged <file>..." to unstage) |
ステージから外すには git restore --staged を使う |
(use "git add <file>..." to update what will be committed) |
コミット予定に入れるには git add を使う |
(use "git restore <file>..." to discard changes in working directory) |
作業ツリーの変更を捨てるには git restore を使う |
(use "git add <file>..." to include in what will be committed) |
コミット予定に含めるには git add を使う |
(use "git push" to publish your local commits) |
手元のコミットを公開するには git push を使う |
(use "git pull" to update your local branch) |
手元のブランチを更新するには git pull を使う |
git restore <file> は編集内容を元に戻す操作で、戻した変更は取り出せません。 打つ前に git diff <file> で差分を確かめておくと落ち着いて進められます。
同じファイルが2つの見出しに出るとき
git add したあとで同じファイルをもう一度編集すると、1つのファイルが「Changes to be committed」と「Changes not staged for commit」の両方に出ます。次は、いろいろな変更を混ぜた状態の実行結果です。
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .gitignore
modified: README.md
new file: new.txt
new file: new2.txt
deleted: old.txt
renamed: name.txt -> renamed.txt
new file: tmp.txt
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
modified: app.txt
modified: new2.txt
deleted: tmp.txt
README.md はステージした時点の内容とその後に足した内容が別々に数えられています。このままコミットすると、入るのはステージした時点の内容だけです。後から足した分も入れたいときは、もう一度 git add README.md を打ちます。
何も変更がないとき・最初のコミット前
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
working tree clean は「コミットしていない変更が1つもない」という意味です。git init した直後は次のように表示されます。
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
Git の管理下にないフォルダで実行すると、次のメッセージになります。cd でリポジトリのフォルダへ移動してから打ち直しましょう。
fatal: not a git repository (or any of the parent directories): .git
git status -s の見方|2文字記号の全パターン一覧
-s(--short)を付けると、1ファイル1行の短い形式になります。上と同じ状態で実行した結果です。
git status -s
M README.md
M app.txt
?? memo.txt
記号は「左=ステージ」「右=作業ツリー」
行頭の2文字は XY と呼ばれ、X(1文字目)がステージの状態、Y(2文字目)が作業ツリーの状態です。M と M は似ていますが、M がどちらの列にあるかで意味が変わります。
| 見た目 | X(ステージ) | Y(作業ツリー) | 読み方 |
|---|---|---|---|
M README.md |
M | 空白 | 変更をステージ済み。追加の変更はない |
M app.txt |
空白 | M | 変更したが、まだステージしていない |
?? memo.txt |
? | ? | 追跡されていない |
色付きの端末では、X の列が緑、Y の列と ?? が赤で表示されます(既定の配色)。
1文字ずつの意味
| 文字 | 意味 |
|---|---|
| 空白 | 変更なし |
M |
変更(modified) |
T |
ファイルの種類が変わった(通常ファイルからシンボリックリンクなど) |
A |
追加(added) |
D |
削除(deleted) |
R |
名前変更(renamed) |
C |
コピー(copied) |
U |
マージが未解決(unmerged) |
? |
追跡されていない |
! |
無視されている |
通常時の組み合わせ一覧(実行して確認したもの)
次の状態を作って git status -s --ignored を実行した結果です。
A .gitignore
MM README.md
M app.txt
A new.txt
AM new2.txt
D old.txt
R name.txt -> renamed.txt
AD tmp.txt
?? memo.txt
!! debug.log
| 記号 | 意味 | この状態を作った操作 | 次の一手 |
|---|---|---|---|
M |
変更したが未ステージ | 追跡中のファイルを編集 | git add |
M |
変更をステージ済み | 編集して git add |
git commit |
MM |
ステージ後にさらに変更 | git add のあと再編集 |
もう一度 git add |
A |
新規ファイルをステージ済み | 新規作成して git add |
git commit |
AM |
新規ステージ後にさらに変更 | git add のあと再編集 |
もう一度 git add |
AD |
新規ステージ後に作業ツリーから削除 | git add のあと rm |
git rm --cached か git restore |
D |
削除をステージ済み | git rm |
git commit |
D |
削除したが未ステージ | rm で削除 |
git rm か git restore |
R |
名前変更をステージ済み | git mv 旧名 新名 |
git commit |
RM |
名前変更後にさらに変更 | git mv のあと編集 |
git add |
T |
種類が変わったが未ステージ | ファイルをシンボリックリンクに置き換え | git add |
T |
種類の変更をステージ済み | 上のあと git add |
git commit |
?? |
追跡されていない | 新規作成のみ | git add か .gitignore |
!! |
無視されている | .gitignore に一致(--ignored 指定時のみ表示) |
そのままでよい |
C(コピー)は今回の検証では再現していません(未実行)。公式ドキュメントの表では「インデックスでコピーされた」状態として載っています。
コンフリクト中の組み合わせ一覧(7種類すべて再現)
マージや rebase でコンフリクトが起きると、X と Y の両方に U・A・D が並ぶ特別な組み合わせになります。us は「いまいるブランチ側」、them は「取り込もうとしている側」です。
| 記号 | 通常表示のラベル | 意味 | 再現した状況 |
|---|---|---|---|
UU |
both modified | 両方が同じファイルを変更 | 同じ行を両ブランチで編集 |
AA |
both added | 両方が同じ名前のファイルを追加 | 両ブランチで both.txt を新規作成 |
DD |
both deleted | 両方で削除(名前変更の元ファイル) | 両ブランチで big.txt を別の名前に変更 |
AU |
added by us | こちら側だけが追加 | こちらが付けた新しい名前 |
UA |
added by them | 相手側だけが追加 | 相手が付けた新しい名前 |
DU |
deleted by us | こちらが削除、相手が変更 | main で削除、side で編集 |
UD |
deleted by them | こちらが変更、相手が削除 | 上を逆向きにマージ |
同じファイルを両方のブランチで別の名前に変え、さらに片方で削除・片方で編集したファイルを用意してマージした結果です。
CONFLICT (rename/rename): big.txt renamed to main-name.txt in HEAD and to side-name.txt in side.
CONFLICT (modify/delete): keep.txt deleted in HEAD and modified in side. Version side of keep.txt left in tree.
Automatic merge failed; fix conflicts and then commit the result.
git status -s
DD big.txt
DU keep.txt
AU main-name.txt
UA side-name.txt
-sb と --porcelain の見方
git status -sb でブランチ情報も1行で見る
-b(--branch)を足すと、先頭に ## で始まるブランチ情報の行が付きます。
git status -sb
## main...origin/main
M README.md
M app.txt
?? memo.txt
## main...origin/main は「main ブランチが origin/main を追跡している」という意味です。未 push のコミットや未取得のコミットがあると、末尾に角かっこで表示されます。
| 1行目の表示 | 意味 |
|---|---|
## main...origin/main |
リモート追跡ブランチと同じ位置 |
## main...origin/main [ahead 1] |
手元が1コミット進んでいる |
## main...origin/main [behind 1] |
手元が1コミット遅れている |
## main...origin/main [ahead 1, behind 1] |
両方にコミットがある |
## nolink |
追跡先(upstream)が設定されていない |
## HEAD (no branch) |
detached HEAD、または rebase の途中 |
毎回 -sb を付けるのが手間なら、設定で既定にできます。次は設定を一時的に与えて実行した結果です。
git -c status.short=true -c status.branch=true status
## main...origin/main [ahead 1]
M app.txt
M memo.txt
常に有効にするなら git config --global status.short true と git config --global status.branch true を設定します。通常表示に戻したいときは git status --long を使います。
git status --porcelain はスクリプト用
--porcelain は、Git のバージョンやユーザー設定が変わっても形式が変わらないことを約束した出力です。見た目は -s とほぼ同じですが、色が付かず、パスは常にリポジトリのルートからの表記になります。シェルスクリプトや CI から読むときはこちらを使います。
git status --porcelain
M README.md
M app.txt
?? memo.txt
「コミットしていない変更があるか」を判定するコピペ用の例です。
if [ -n "$(git status --porcelain)" ]; then
echo "未コミットの変更があります"
else
echo "作業ツリーはクリーンです"
fi
ファイル名に空白や改行が入る可能性があるときは、区切りを NUL 文字にする -z を組み合わせます。cat -v で見えるようにした実行結果です(^@ が NUL)。
git status -z | cat -v
M README.md^@ M app.txt^@?? memo.txt^@
--porcelain=v2 はさらに詳しい
--porcelain=v2 --branch にすると、ブランチ情報が # で始まるヘッダーになり、各ファイルのモードやオブジェクト ID まで出力されます。
git status --porcelain=v2 --branch
# branch.oid 562807a2359ec3d2078bc994856e77c213233347
# branch.head main
# branch.upstream origin/main
# branch.ab +0 -0
1 M. N... 100644 100644 100644 4286f428e3b19fe84de503916ce0e7dc8deefea1 5b0cb7d0759ff618bafe41145e9fe9370c7812ee README.md
1 .M N... 100644 100644 100644 78981922613b2afb6025042ff6bd878ac1994e85 78981922613b2afb6025042ff6bd878ac1994e85 app.txt
? memo.txt
| 行の先頭 | 意味 |
|---|---|
# branch.oid |
現在のコミット ID |
# branch.head |
現在のブランチ名(detached のときは (detached)) |
# branch.upstream |
追跡先のブランチ |
# branch.ab +0 -0 |
ahead と behind の数 |
1 |
通常の変更。続く M. が XY(v2 では空白の代わりに .) |
u |
コンフリクト中(実行結果では u UU N... ... と表示) |
? |
追跡されていないファイル |
3つの形式の使い分け
| 形式 | 向いている場面 | 特徴 |
|---|---|---|
git status |
状況をじっくり確認したい | ヒントつきで次のコマンドがわかる |
git status -sb |
日々の確認を素早くしたい | 1ファイル1行。ブランチ情報も1行 |
git status --porcelain |
スクリプト・CI で読みたい | 形式が固定。色なし |
git status --porcelain=v2 --branch |
ツールで細かく解析したい | ahead / behind やオブジェクト ID を含む |
ahead・behind・diverged の見方
ブランチ名の次の行は、手元のブランチとリモート追跡ブランチ(origin/main など)のコミット数の差を表します。
ahead(手元が進んでいる)
コミットしてまだ push していない状態です。
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
日本語表示では次のようになりました。
ブランチ main
このブランチは 'origin/main' よりも1コミット進んでいます。
(use "git push" to publish your local commits)
behind(手元が遅れている)
別の人が push したあと、git fetch を実行した状態です。
On branch main
Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
ブランチ main
このブランチは 'origin/main' に比べて1コミット遅れています。fast-forwardすることができます。
can be fast-forwarded は「手元に独自のコミットがないので、ブランチの位置を前へ進めるだけで追いつける」という意味です。
diverged(両方にコミットがある)
behind の状態で手元でもコミットすると、次の表示になります。
On branch main
Your branch and 'origin/main' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" if you want to integrate the remote branch with yours)
nothing to commit, working tree clean
have 1 and 1 different commits は「手元だけに1つ、リモートだけに1つ」という順番です。-sb では [ahead 1, behind 1] と表示されます。履歴を一直線にまとめたいなら git pull --rebase、マージコミットを作るなら git pull --no-rebase を選びます。
「up to date」は fetch した時点の話
git status はリモートに問い合わせをしません。 比べている相手は、手元に保存されている「最後に fetch したときの origin/main」です。今回の検証でも、別のクローンから push した直後は次のように差が表示されず、git fetch を実行して初めて [behind 1] に変わりました。
## main...origin/main
git fetch
git status -sb
## main...origin/main [behind 1]
リモートの最新状況を知りたいときは、git fetch を打ってから git status の順にします。
追跡先がないブランチ
git switch -c nolink で作ったばかりのブランチには追跡先がないため、ahead / behind の行そのものが表示されません。
On branch nolink
nothing to commit, working tree clean
git push -u origin nolink で push すると追跡先が設定され、次回から差が表示されます。
マージコンフリクト中の git status の見方
main と feature の両方で app.txt の同じ行を変更し、git merge feature を実行しました。
Auto-merging app.txt
CONFLICT (content): Merge conflict in app.txt
Automatic merge failed; fix conflicts and then commit the result.
この直後の git status です。
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: app.txt
no changes added to commit (use "git add" and/or "git commit -a")
git status -sb では次のように1行で表示されます。
## main...origin/main [ahead 1]
UU app.txt
| 表示 | 意味 | 次に打つコマンド |
|---|---|---|
You have unmerged paths. |
解決していないコンフリクトがある | ファイルを開いて編集する |
(fix conflicts and run "git commit") |
直してからコミットすればマージ完了 | 編集 → git add → git commit |
(use "git merge --abort" to abort the merge) |
マージ前の状態に戻せる | git merge --abort |
Unmerged paths: |
コンフリクト中のファイル一覧 | 1つずつ解決する |
both modified: app.txt |
両方のブランチが app.txt を変更した | マーカーを消して内容を決める |
ファイルを編集して git add app.txt を実行すると、表示が次のように変わります。
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
modified: app.txt
All conflicts fixed but you are still merging. は「解決は終わったが、マージのコミットがまだ」という合図です。git commit を打てばマージが完了します。
削除と変更がぶつかった場合や、両方が同じ名前のファイルを追加した場合は、ラベルが変わります。
Unmerged paths:
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by them: README.md
both added: both.txt
deleted by them は「相手側が削除し、こちらは変更した」状態です。残すなら git add README.md、削除を受け入れるなら git rm README.md を選びます。
rebase 中の git status の見方
feature ブランチで git rebase main を実行し、コンフリクトで止まったときの git status です。
interactive rebase in progress; onto 2c15f49
Last command done (1 command done):
pick 49305fd f
No commands remaining.
You are currently rebasing branch 'feature' on '2c15f49'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: app.txt
no changes added to commit (use "git add" and/or "git commit -a")
| 表示 | 意味 |
|---|---|
interactive rebase in progress; onto 2c15f49 |
rebase の途中。2c15f49 の上にコミットを積み直している |
Last command done (1 command done): |
直前に処理したコミット(ここで止まっている) |
No commands remaining. |
残りのコミットはない(これが最後の1つ) |
You are currently rebasing branch 'feature' on '2c15f49'. |
feature を 2c15f49 の上に移している最中 |
(fix conflicts and then run "git rebase --continue") |
直して add したら --continue で続行 |
(use "git rebase --skip" to skip this patch) |
このコミットを飛ばす |
(use "git rebase --abort" to check out the original branch) |
rebase 前の状態に戻る |
-i を付けていなくても、Git 2.43.0 では interactive rebase in progress と表示されました。rebase 中は一時的にブランチから離れているため、git status -sb の1行目は次のようになります。
## HEAD (no branch)
UU app.txt
ファイルを直して git add app.txt を実行すると、ヒントが1行に変わります。
You are currently rebasing branch 'feature' on '2c15f49'.
(all conflicts fixed: run "git rebase --continue")
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: app.txt
日本語表示では、この行が「(全てのコンフリクトが修正されました: "git rebase --continue"を実行してください)」に対応します。git rebase --continue を実行すると rebase が完了し、次の表示に戻りました。
On branch feature
nothing to commit, working tree clean
マージ中は「git commit」で締め、rebase 中は「git rebase --continue」で締める、という違いを git status のヒントが毎回教えてくれます。
detached HEAD の git status の見方
git checkout HEAD~1 のように、ブランチ名ではなくコミットを直接指定して切り替えると、detached HEAD(ブランチから離れた状態)になります。
HEAD detached at 19470b9
nothing to commit, working tree clean
-sb では次のとおりです。
## HEAD (no branch)
この状態でコミットすると、1行目の at が from に変わりました。
HEAD detached from 19470b9
nothing to commit, working tree clean
| 表示 | 意味 |
|---|---|
HEAD detached at 19470b9 |
19470b9 のコミットをそのまま見ている |
HEAD detached from 19470b9 |
19470b9 から離れたあと、新しいコミットを作った |
from の状態でブランチに戻ると、Git は作ったコミットの残し方を案内してくれます。
Warning: you are leaving 1 commit behind, not connected to
any of your branches:
b1b6906 det-commit
If you want to keep it by creating a new branch, this may be a good time
to do so with:
git branch <new-branch-name> b1b6906
Switched to branch 'main'
| やりたいこと | コマンド |
|---|---|
| 元のブランチへ戻る | git switch - または git switch main |
| いまの位置から新しいブランチを作って続ける | git switch -c <新しいブランチ名> |
| 離れたあとに作ったコミットを残す | git branch <新しいブランチ名> <コミットID> |
過去の状態を見るだけなら detached HEAD のままで問題ありません。コミットを残したくなったら git switch -c でブランチを作ると覚えておけば十分です。
便利なオプションと設定
| やりたいこと | コマンド | 補足 |
|---|---|---|
| 短縮表示にする | git status -s |
1ファイル1行 |
| 短縮表示+ブランチ情報 | git status -sb |
1行目に ## |
| スクリプト用の固定形式 | git status --porcelain |
v2 は --porcelain=v2 |
| 無視されたファイルも表示 | git status --ignored |
-s では !! |
| 未追跡ファイルを表示しない | git status -uno |
追跡中の変更だけ見たいとき |
| 未追跡フォルダの中身まで表示 | git status -uall |
既定はフォルダ名だけ |
| 特定のフォルダだけ見る | git status -s dir/ |
パスで絞り込み |
| stash の件数も表示 | git status --show-stash |
末尾に1行追加 |
| ステージ済みの差分も表示 | git status -v |
末尾に diff が付く |
| 日本語ファイル名をそのまま表示 | git config --global core.quotepath false |
下の例を参照 |
未追跡フォルダは -uall で中身まで表示
新しいフォルダを作ると、既定ではフォルダ名だけが表示されます。
git status -s
?? dir/
?? "\346\227\245\346\234\254\350\252\236.txt"
git status -s -uall
?? dir/a.txt
?? dir/sub/b.txt
?? "\346\227\245\346\234\254\350\252\236.txt"
日本語ファイル名が数字の並びになるとき
上の "\346\227\245..." は、日本語のファイル名(日本語.txt)がエスケープされた表示です。core.quotepath を false にすると、そのまま表示されます。
git -c core.quotepath=false status -s
?? dir/
?? 日本語.txt
常に有効にするには git config --global core.quotepath false を設定します。
stash の件数を確認する
git status --show-stash
nothing to commit, working tree clean
Your stash currently has 1 entry
迷いやすい表示と読み方
| 見えた表示 | 起きていること | 次の一手 |
|---|---|---|
同じファイルが2つの見出しに出る(MM) |
git add のあとに再編集した |
もう一度 git add |
no changes added to commit (use "git add" and/or "git commit -a") |
変更はあるがステージが空 | git add してからコミット |
nothing added to commit but untracked files present |
未追跡ファイルだけがある | git add か .gitignore |
Your branch is up to date なのに push で差が出る |
fetch してからリモートが進んだ | git fetch してから再確認 |
.gitignore に書いたのに M で出る |
すでに追跡中のファイルは無視の対象にならない | git rm --cached <file> で追跡を外す |
| フォルダを作ったのに出てこない | Git は空のフォルダを追跡しない | 中にファイルを1つ置く |
ファイル名が "\346..." になる |
日本語名がエスケープされている | core.quotepath false |
HEAD detached at ... |
コミットを直接チェックアウトした | git switch - で戻る |
コミット前のチェックリスト
| 確認すること | 見る場所 |
|---|---|
| いるブランチは合っているか | 1行目の On branch |
| 入れたい変更がすべてステージされているか | Changes to be committed |
| 入れたくないファイルがステージに混ざっていないか | Changes to be committed |
| ステージ後に再編集したファイルがないか | 2つの見出しに同じ名前がないか(MM・AM) |
| 追加し忘れた新規ファイルがないか | Untracked files |
| コンフリクトが残っていないか | Unmerged paths |
よくある質問
Q. Untracked files に出たファイルは、放っておいても大丈夫ですか?
A. はい、Git の履歴には入らないだけで、ファイルは手元にそのまま残ります。履歴に入れたいなら git add、ログや一時ファイルのように管理しないものなら .gitignore に書いておくと、一覧がすっきりして必要な変更を見つけやすくなります。
Q. Changes not staged for commit のままコミットするとどうなりますか?
A. その変更はコミットに入りません。コミットに入るのは「Changes to be committed」に並んでいるものだけです。追跡中のファイルの変更をまとめて入れたいときは git add -u、新規ファイルも含めるなら git add -A を使ってからコミットします。
Q. -s の「M 」と「 M」はどう見分ければよいですか? A. M が行頭にあればステージ済み、1文字ぶん右にずれていれば未ステージです。色付きの端末なら、ステージ済みは緑、未ステージは赤で表示されるので、色でも見分けられます。
Q. git status を日本語で表示できますか?
A. 環境によります。今回 Ubuntu 24.04 の日本語言語パックで試したところ、「コミット予定の変更点:」「追跡されていないファイル:」など一部の行だけが日本語になりました。訳される範囲は環境ごとに違うため、この記事の対応表で英語の見出しを読めるようにしておくのがおすすめです。英語に固定したいときは LANG=C git status のように実行します。
まとめ
- git status は「作業ツリー・ステージ・HEAD・リモート追跡ブランチ」の差を順に報告している
- Changes to be committed はコミット予定、Changes not staged for commit は未ステージ、Untracked files は未追跡
- 見出しの下のかっこ書きが、次に打つコマンドの案内になっている
- -s の2文字は「左がステージ、右が作業ツリー」。
??は未追跡、UUはコンフリクト中 - -sb なら ahead / behind も1行でわかり、スクリプトには形式が固定の --porcelain を使う
- up to date は最後に fetch した時点との比較。最新を知りたいときは git fetch を先に打つ
- マージ中は git commit、rebase 中は git rebase --continue、detached HEAD は git switch で次へ進む
本記事の内容は、ご自由にお使いください。
ご利用の際は、出典として本ページへのリンクを記載いただけますようお願いします。
(記載例)出典:株式会社RJC「git statusの見方|Untracked等の意味と-s短縮表示の記号一覧」
株式会社RJCでは、git status の読み方のような基礎を仲間と学び合っています。こうした知識を共有しながら、日々技術を磨いています。
株式会社RJC ― SI事業・SES事業・AI駆動開発。RJCは一緒に成長を楽しめる会社です。
WE ARE HIRING
RJCで一緒に開発しながら、
成長を楽しみませんか?
RJCは、Web・モバイル・AIを活用した開発プロジェクトで、テックリードやPM・PMOも活躍するシステム開発会社です。会社を知る、待遇を確かめる、話を聞いてみる。気になるところ見てみてください!
- 127日年間休日
- 12時間平均残業時間
- 毎日ガチャ遊びココロも大切にする福利厚生。アマギフなどの賞品ラインナップ!
ほかにも、チケットレストラン、書籍読み放題、2年ごとの慰労報奨(休暇 or 金一封)、11期連続の黒字決算。