git はソースコードの変更を記録するコマンドです。`git status` の読み方、`add` と `commit` の違い、`git log` での履歴の見方を、ブラウザ上のターミナルで打ちながら確認できます。
最終更新: 2026-09-06
git <サブコマンド> [オプション]
git は1つのコマンドではなく、サブコマンドの集まりです。
毎日使うのは、この後に出てくる5つだけです。
何をするにも git status から始めます。
$ git status
On branch main
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: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
notes.txt
no changes added to commit (use "git add" and/or "git commit -a")
読み取れることは3つです。
| 見出し | 意味 |
|---|---|
On branch main | いま main で作業している |
Changes not staged for commit | 直したが、まだ記録の対象に選んでいない |
Untracked files | git がまだ一度も見ていないファイル |
短く見たいときは -s を付けます。
$ git status -s
M README.md
?? notes.txt
M は変更、?? は未追跡です。
どこを直したのかは git diff で分かります。
$ git diff
diff --git a/README.md b/README.md
index 4f908a3..3b65e7d 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
# project
A small example project.
+Run npm start to begin.
+ が付いた行が、追加した行です。
記録する前に必ずこれを見てください。
消したつもりのないものが混ざっていないか、ここでしか気づけません。
記録は2段階です。 まず、記録したいファイルを選びます。
$ git add README.md
$ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
notes.txt
README.md が Changes to be committed(ステージング)に移りました。
選んだものだけを、1つの記録として確定します。
$ git commit -m "Explain how to start the app"
[main 212b4a4] Explain how to start the app
1 file changed, 1 insertion(+)
212b4a4 はこのコミットに付いた名前で、実行するたびに変わります。
notes.txt は選んでいないので、記録には入っていません。
$ git status -s
?? notes.txt
この「選んでから確定する」2段階が git の中心です。 1回の作業で複数のことを直してしまっても、関係するファイルだけを選んで、意味のまとまりごとに記録を分けられます。
$ git log --oneline
212b4a4 (HEAD -> main) Explain how to start the app
6606c5f add a description
77860e9 first commit
新しいものが上です。
--oneline を付けないと、作者と日時を含む詳しい形式になります。
| サブコマンド | 何をするか |
|---|---|
git status | いまどうなっているかを見る |
git diff | 直した中身を見る |
git add <ファイル> | 記録するものを選ぶ |
git commit -m "..." | 選んだものを記録する |
git log --oneline | 履歴を見る |
git switch -c <名前> | 新しいブランチを作って移る |
git restore <ファイル> | 直した内容を捨てて元に戻す |
git は、戻れるようにしてから進むためのコマンドです。
| 場面 | 打ち方 |
|---|---|
| 作業を始める前に状態を確かめる | git status |
| 何を直したか思い出す | git diff |
| キリのいいところで記録する | git add <ファイル> → git commit -m "..." |
| 直前のメッセージを書き直す | git commit --amend -m "..." |
| 変更を捨てる | git restore <ファイル> |
git add しないと記録されません。
ファイルを保存しただけでは履歴に残りません。
git commit の直前に git status を見て、Changes to be committed に入っているかを確かめてください。
git add . は打つ前に git status を。
. はいまいる場所より下の全部です。
秘密の鍵やビルドの成果物まで入ってしまうことがあるので、まず何が入るのかを見てください。
メッセージは後から読む人のために書きます。
fix や update だけでは、履歴を見返したときに何をしたのか分かりません。
「何をしたか」ではなく「なぜそうしたか」を1行で書くと、後から効いてきます。
git は大きな道具です。
このページで扱ったのは、毎日使う入口の部分だけです。
ブランチをまたいだ作業や、取り消し方の使い分けは、下のチュートリアルとコースで順に扱っています。
webterm.appこのサイト
Git入門
Gitの基本操作を学ぶ
Git基礎
ブランチと履歴操作を学ぶ
learn.webterm.app別のサイト
