| サンプル集 |
|
■VC ■C# ■Java ■BorlandC ■LinuxC ■MS-DOS ■bash ■Excel VBA ■VBScript ■PHP ■HTML ■perl ■iPhone ■Android ■Lua ■WordPress ■PowerShell ■Python ■Flutter ■Rust ■Node.js ■other |
| Linuxコマンド |
| 用語集 |
| debian メモ |
| apache2 メモ |
| MySQL メモ |
| Oracle メモ |
| PostgreSQL |
| HOME |
Git add/commit/status/diff/logコマンドを使ってみます。

◆環境
| OS | Windows 10 Home 22H2 64bit |
|---|---|
| Git | 2.50.1.windows.1 |
管理したいファイルを作成します。
| index.html | ||
|
git addコマンドを実行します。 何も表示されませんでしたが問題なく動作したのでしょうか。
>git add .
>
>
git commitコマンドを実行します。
>git commit
エディターが開きました。 first commitと入力しエディターを閉じます。

コマンドプロンプトにメッセージが表示されました。
[master (root-commit) e9275d3] first commit
1 file changed, 1 insertion(+)
create mode 100644 index.html
1 file changed, 1 insertion(+)
create mode 100644 index.html
変更の状態を確認します。
>git status
On branch master
nothing to commit, working tree clean
On branch master
nothing to commit, working tree clean
index.htmlを編集します。
| index.html | ||
|
変更状態を確認したところステージに追加されていない変更がある(Changes not staged for commit)と表示されました。
>git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working director
y)
modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working director
y)modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
git addコマンドを実行します。 今回も何も表示されませんでしたが問題なく動作したのでしょうか。
>git add index.html
>
>
変更状態を確認したところコミットすべき変更がある(Changes to be committed)と表示されました。
>git status
On branch master
Changes to be committed:
(use "git restore --staged..." to unstage)
modified: index.html
On branch master
Changes to be committed:
(use "git restore --staged
modified: index.html
git commitコマンドを実行してみます。
>git commit -m htmlタグを追加
[master fe8e695] htmlタグを追加
1 file changed, 5 insertions(+)
[master fe8e695] htmlタグを追加
1 file changed, 5 insertions(+)
変更の状態を確認します。
>git status
On branch master
nothing to commit, working tree clean
On branch master
nothing to commit, working tree clean
index.htmlを編集します。
| index.html | ||
|
git diffコマンドで差分を確認します。
>git diff index.html
diff --git a/index.html b/index.html
index 27ee115..a742c71 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,8 @@
<!doctype html>
<html dir="ltr" lang="ja">
+<head>
+ <title>Hello Git!</title>
+</head>
<body>
<h1>Hello Git!</h1>
</body>
diff --git a/index.html b/index.html
index 27ee115..a742c71 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,8 @@
<!doctype html>
<html dir="ltr" lang="ja">
+<head>
+ <title>Hello Git!</title>
+</head>
<body>
<h1>Hello Git!</h1>
</body>
git addしてgit diffをしたところ何も表示されませんでした。
>git add index.html
>git diff
>
>git diff
>
git diff --stagedコマンドでは差分が表示されました。
>git diff --staged
diff --git a/index.html b/index.html
index 27ee115..a742c71 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,8 @@
<!doctype html>
<html dir="ltr" lang="ja">
+<head>
+ <title>Hello Git!</title>
+</head>
<body>
<h1>Hello Git!</h1>
</body>
diff --git a/index.html b/index.html
index 27ee115..a742c71 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,8 @@
<!doctype html>
<html dir="ltr" lang="ja">
+<head>
+ <title>Hello Git!</title>
+</head>
<body>
<h1>Hello Git!</h1>
</body>
git commitした後git diff --stagedとgit diffを実行してみましたがどちらも何も表示されませんでした。
>git commit -m headを追加
[master 142a22e] headを追加
1 file changed, 3 insertions(+)
>git diff --staged
>git diff
[master 142a22e] headを追加
1 file changed, 3 insertions(+)
>git diff --staged
>git diff
git logコマンドで変更履歴を確認します。
>git log
commit 142a22ed7ed8fc0b69398e7d4be45d046d36c418 (HEAD -> master)
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:33:44 2025 +0900
headを追加
commit fe8e695c2f23714dd2e866e64d87378b691fa0d1
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:01:52 2025 +0900
htmlタグを追加
commit e9275d3770222dde3913eb2753a5165c59852a7d
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 17:36:06 2025 +0900
first commit
commit 142a22ed7ed8fc0b69398e7d4be45d046d36c418 (HEAD -> master)
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:33:44 2025 +0900
headを追加
commit fe8e695c2f23714dd2e866e64d87378b691fa0d1
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:01:52 2025 +0900
htmlタグを追加
commit e9275d3770222dde3913eb2753a5165c59852a7d
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 17:36:06 2025 +0900
first commit
git log --onelineコマンドを使ってみます。
>git log --oneline
142a22e (HEAD -> master) headを追加
fe8e695 htmlタグを追加
e9275d3 first commit
142a22e (HEAD -> master) headを追加
fe8e695 htmlタグを追加
e9275d3 first commit
-pオプションを指定してファイルを指定すると差分まで表示されます。
>git log -p index.html
commit 142a22ed7ed8fc0b69398e7d4be45d046d36c418 (HEAD -> master)
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:33:44 2025 +0900
headを追加
diff --git a/index.html b/index.html
index 27ee115..a742c71 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,8 @@
<!doctype html>
<html dir="ltr" lang="ja">
+<head>
+ <title>Hello Git!</title>
+</head>
<body>
<h1>Hello Git!</h1>
</body>
commit fe8e695c2f23714dd2e866e64d87378b691fa0d1
Author: github user name <github-user@mail.com>
:
以下略
commit 142a22ed7ed8fc0b69398e7d4be45d046d36c418 (HEAD -> master)
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:33:44 2025 +0900
headを追加
diff --git a/index.html b/index.html
index 27ee115..a742c71 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,8 @@
<!doctype html>
<html dir="ltr" lang="ja">
+<head>
+ <title>Hello Git!</title>
+</head>
<body>
<h1>Hello Git!</h1>
</body>
commit fe8e695c2f23714dd2e866e64d87378b691fa0d1
Author: github user name <github-user@mail.com>
:
以下略
-nオプションで表示するコミット数を指定できます。
>git log -n 2
commit 142a22ed7ed8fc0b69398e7d4be45d046d36c418 (HEAD -> master)
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:33:44 2025 +0900
headを追加
commit fe8e695c2f23714dd2e866e64d87378b691fa0d1
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:01:52 2025 +0900
htmlタグを追加
commit 142a22ed7ed8fc0b69398e7d4be45d046d36c418 (HEAD -> master)
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:33:44 2025 +0900
headを追加
commit fe8e695c2f23714dd2e866e64d87378b691fa0d1
Author: github user name <github-user@mail.com>
Date: Sat Sep 20 18:01:52 2025 +0900
htmlタグを追加
一通り動作しました。
Copyright (C) 2025 ymlib.com
