0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Git] 動作を試す 実行例5:logでコミット履歴を見る・検索する

Last updated at Posted at 2023-04-28

Gitの動作を理解するために、Gitのコマンドを実際に試して、結果を見てみました。

1つの記事内で一連のGitコマンドが完結しているので、これら一連のコマンドを順に実行させて結果を見ることで、一連のGitの動作を実際に体感でき、一通り独習することが可能です。

※前回記事のリポジトリ状態からの続きになっています。

前回記事へ 目次へ:Git関連記事のまとめページ 次回記事へ

実行例

git log よく使うオプションまとめ
https://qiita.com/take4s5i/items/15d8648405f4e7ea3039

git log
↓
結果: 
commit 20bbab7d3d5cb79bec87d68941733d51fd72fd3c (HEAD -> master)
Author: person1 <person1@abc.def>
Date:   Sun Jan 1 18:09:17 2023 +0900

    message3

commit 00cad7159948154b9a0e2011d052584bedd643c9
Author: person1 <person1@abc.def>
Date:   Sun Jan 1 18:08:04 2023 +0900

    message2

commit 4ace1948833337dd53a02da7a30abce5235ac566
Author: person1 <person1@abc.def>
Date:   Sun Jan 1 18:07:47 2023 +0900

    message1

git log -2
↓
結果: 
commit 20bbab7d3d5cb79bec87d68941733d51fd72fd3c (HEAD -> master)
Author: person1 <person1@abc.def>
Date:   Sun Jan 1 18:09:17 2023 +0900

    message3

commit 00cad7159948154b9a0e2011d052584bedd643c9
Author: person1 <person1@abc.def>
Date:   Sun Jan 1 18:08:04 2023 +0900

    message2
    
git log --oneline
↓
結果: 
20bbab7 (HEAD -> master) message3
00cad71 message2
4ace194 message1

git log --oneline --graph
↓
結果: 
* 20bbab7 (HEAD -> master) message3
* 00cad71 message2
* 4ace194 message1

git log --oneline --graph --stat
↓
結果: 
* 20bbab7 (HEAD -> master) message3
|  test1.txt | 1 +
|  test2.txt | 2 +-
|  2 files changed, 2 insertions(+), 1 deletion(-)
* 00cad71 message2
|  test1.txt | 1 +
|  test2.txt | 1 +
|  2 files changed, 2 insertions(+)
* 4ace194 message1
   test1.txt | 1 +
   1 file changed, 1 insertion(+)

-----

※指定ファイルが変更されたコミットを検索する
git log --oneline test2.txt
↓
結果: 
20bbab7 (HEAD -> master) message3
00cad71 message2

git log --oneline -p test2.txt
↓
結果: 
20bbab7 (HEAD -> master) message3
diff --git a/test2.txt b/test2.txt
index 21a6906..1facb47 100644
--- a/test2.txt
+++ b/test2.txt
@@ -1 +1 @@
-Sample-Added-21
+Sample-Added-**21
00cad71 message2
diff --git a/test2.txt b/test2.txt
new file mode 100644
index 0000000..21a6906
--- /dev/null
+++ b/test2.txt
@@ -0,0 +1 @@
+Sample-Added-21

-----

※任意の文字列を引数にして、その文字列が追加・削除されたコミットのみを抜き出す
git log --oneline -SAdded-12
↓
結果: 
00cad71 message2

git log --oneline -S"Added-12"
↓
結果: 
00cad71 message2

git log --oneline -SAdded-12 -p
↓
結果: 
00cad71 message2
diff --git a/test1.txt b/test1.txt
index 046a699..0116b50 100644
--- a/test1.txt
+++ b/test1.txt
@@ -1 +1,2 @@
 Sample-Added-11
+Sample-Added-12

-----

git log --oneline -SAdded-21
↓
結果: 
20bbab7 (HEAD -> master) message3
00cad71 message2

git log --oneline -SAdded-21 --stat
↓
結果: 
20bbab7 (HEAD -> master) message3
 test2.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
00cad71 message2
 test2.txt | 1 +
 1 file changed, 1 insertion(+)

git log --oneline -SAdded-21 -p
↓
結果: 
20bbab7 (HEAD -> master) message3
diff --git a/test2.txt b/test2.txt
index 21a6906..1facb47 100644
--- a/test2.txt
+++ b/test2.txt
@@ -1 +1 @@
-Sample-Added-21
+Sample-Added-**21
00cad71 message2
diff --git a/test2.txt b/test2.txt
new file mode 100644
index 0000000..21a6906
--- /dev/null
+++ b/test2.txt
@@ -0,0 +1 @@
+Sample-Added-21

環境

Windows 10、PortableGit-2.40.0-64-bitを使用、全てローカルPC上で実施、GitHub等は不使用。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?