コマンドはどうですかgit log -p
、git show
、およびgit diff
関連していて、なぜ一方が他方よりも使用されるのでしょうか。
次の4つのコミットを持つリポジトリがあるとします。
commitd-最後のコミット
commitc
commitb
coomita-初期コミット
次のgitコマンドの違いは何ですか?:
git log -p commitb commitd
git show commitb commitd
git diff commitb commitd
git log -p commitd commitb
git show commitd commitb
git diff commitd commitb
git log -p commitb..commitd
git show commitb..commitd
git diff commitb..commitd
git log -p commitd..commitb
git show commitd..commitb
git diff commitd..commitb
git log -p commitb...commitd
git show commitb...commitd
git diff commitb...commitd
git log -p commitd...commitb
git show commitd...commitb
git diff commitd...commitb
_git log A B
_は、両方のコミットA
とB
の履歴を示します(基本的に、各コミットの履歴の和集合を生成します)。通常、_git log A..B
_が必要です。これは_git log ^B A
_と書くこともできます(Aから到達可能なすべてのものを表示しますが、Bからはnot(_^
_))。この範囲は空にすることもできます(たとえば、B
から到達可能なすべてのコミットはA
からも到達可能であるため、_B..A
_は空になります)。したがって、「間違った」引数とともに使用すると、_git log
_からも出力が得られません。
_git show
_は非常に用途の広いコマンドであり、引数に応じて異なる出力を生成します。 1つまたは複数のコミットを渡すことができ、コミット情報(作成者、タイムスタンプ、コミットメッセージ、前のコミットとの差分)が表示されます。 _a..d
_などのコミット範囲が解決され、各コミットが個別に表示されます。パスを渡すこともでき、_git show
_はファイルの内容を表示します。構文_commit:path/to/file
_を使用して、特定のリビジョンのファイルを指定することもできます。ディレクトリを渡すと、_git show
_はそのディレクトリを変更した最後のコミットのコミット情報を表示します。
_git diff
_は通常、2つのツリーまたは2つのファイルを比較することを想定しています。 (引数を取らず、代わりにインデックス/ステージング領域を比較することもできます)。コミットは自動的にラップ解除対応するツリーに組み込まれます(ツリーオブジェクトはリポジトリの特定の状態を記述します)。構文_A..B
_は、差分の場合は_A B
_にサイレントに解決され、commit/tree A
からB
に取得するために必要な変更が表示されます。
範囲_A...B
_は、「AまたはBから到達可能なすべてのコミットが、両方からは到達できない」ことを意味します。
git log
_と一緒に使用すると、それらのコミットが表示されます。ほとんどの場合、分岐したブランチで使用した場合にのみ意味があります。つまり、「2つのブランチ間で異なるすべてを表示しますが、両方のブランチに共通するコミットは非表示にします」。git diff
_の場合、この構文はgit diff $(git merge-base A B) B
の構文糖衣構文です。つまり、「B
の履歴が分岐してからのA
の変更」です。git show
_を使用すると、その範囲内の単一のコミットごとにコミット情報を取得するだけです。それでも不明な点がある場合は、コメントでお知らせください。
元の質問で投稿したリポジトリの出力は次のとおりです。
_$ git init
Initialized empty Git repository in ...
$ cd SO
$ ls
$ echo a > a
$ git add a
$ git commit
[master (root-commit) 7b66fe5] initial commit
1 file changed, 1 insertion(+)
create mode 100644 a
$ git tag a
$ echo b >> a
$ echo b > b
$ git add a b
$ git commit
[master ee884fe] commit b
2 files changed, 2 insertions(+)
create mode 100644 b
$ git tag b
$ echo c >> a
$ echo c >> b
$ echo c > c
$ git add a b c
$ git commit
[master 8abaaff] commit c
3 files changed, 3 insertions(+)
create mode 100644 c
$ git tag c
$ echo d >> a
$ echo d > b
$ git add a b
$ git commit
[master 08adc85] commit d
2 files changed, 2 insertions(+), 2 deletions(-)
$ git tag d
$ git log -p b d --
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
commit 8abaaff681be0bcaa16c946feb2989959348c9f4
Author: ...
Date: Mon Sep 1 17:21:40 2014 +0200
commit c
diff --git a/a b/a
index 422c2b7..de98044 100644
--- a/a
+++ b/a
@@ -1,2 +1,3 @@
a
b
+c
diff --git a/b b/b
index 6178079..9ddeb5c 100644
--- a/b
+++ b/b
@@ -1 +1,2 @@
b
+c
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
commit ee884fea5d0266280845348175ac0af5083a9bbf
Author: ...
Date: Mon Sep 1 17:21:05 2014 +0200
commit b
diff --git a/a b/a
index 7898192..422c2b7 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
a
+b
diff --git a/b b/b
new file mode 100644
index 0000000..6178079
--- /dev/null
+++ b/b
@@ -0,0 +1 @@
+b
commit 7b66fe5999039c53ffbe5a5ffe07c13a5c213455
Author: ...
Date: Mon Sep 1 17:20:39 2014 +0200
initial commit
diff --git a/a b/a
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/a
@@ -0,0 +1 @@
+a
$ git show b d --
commit ee884fea5d0266280845348175ac0af5083a9bbf
Author: ...
Date: Mon Sep 1 17:21:05 2014 +0200
commit b
diff --git a/a b/a
index 7898192..422c2b7 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
a
+b
diff --git a/b b/b
new file mode 100644
index 0000000..6178079
--- /dev/null
+++ b/b
@@ -0,0 +1 @@
+b
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
$ git diff b d --
diff --git a/a b/a
index 422c2b7..d68dd40 100644
--- a/a
+++ b/a
@@ -1,2 +1,4 @@
a
b
+c
+d
diff --git a/b b/b
index 6178079..4bcfe98 100644
--- a/b
+++ b/b
@@ -1 +1 @@
-b
+d
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
$ git log -p d b --
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
commit 8abaaff681be0bcaa16c946feb2989959348c9f4
Author: ...
Date: Mon Sep 1 17:21:40 2014 +0200
commit c
diff --git a/a b/a
index 422c2b7..de98044 100644
--- a/a
+++ b/a
@@ -1,2 +1,3 @@
a
b
+c
diff --git a/b b/b
index 6178079..9ddeb5c 100644
--- a/b
+++ b/b
@@ -1 +1,2 @@
b
+c
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
commit ee884fea5d0266280845348175ac0af5083a9bbf
Author: ...
Date: Mon Sep 1 17:21:05 2014 +0200
commit b
diff --git a/a b/a
index 7898192..422c2b7 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
a
+b
diff --git a/b b/b
new file mode 100644
index 0000000..6178079
--- /dev/null
+++ b/b
@@ -0,0 +1 @@
+b
commit 7b66fe5999039c53ffbe5a5ffe07c13a5c213455
Author: ...
Date: Mon Sep 1 17:20:39 2014 +0200
initial commit
diff --git a/a b/a
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/a
@@ -0,0 +1 @@
+a
$ git show d b --
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
commit ee884fea5d0266280845348175ac0af5083a9bbf
Author: ...
Date: Mon Sep 1 17:21:05 2014 +0200
commit b
diff --git a/a b/a
index 7898192..422c2b7 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
a
+b
diff --git a/b b/b
new file mode 100644
index 0000000..6178079
--- /dev/null
+++ b/b
@@ -0,0 +1 @@
+b
$ git diff d b --
diff --git a/a b/a
index d68dd40..422c2b7 100644
--- a/a
+++ b/a
@@ -1,4 +1,2 @@
a
b
-c
-d
diff --git a/b b/b
index 4bcfe98..6178079 100644
--- a/b
+++ b/b
@@ -1 +1 @@
-d
+b
diff --git a/c b/c
deleted file mode 100644
index f2ad6c7..0000000
--- a/c
+++ /dev/null
@@ -1 +0,0 @@
-c
$ git log -p b..d --
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
commit 8abaaff681be0bcaa16c946feb2989959348c9f4
Author: ...
Date: Mon Sep 1 17:21:40 2014 +0200
commit c
diff --git a/a b/a
index 422c2b7..de98044 100644
--- a/a
+++ b/a
@@ -1,2 +1,3 @@
a
b
+c
diff --git a/b b/b
index 6178079..9ddeb5c 100644
--- a/b
+++ b/b
@@ -1 +1,2 @@
b
+c
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
$ git show b..d --
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
commit 8abaaff681be0bcaa16c946feb2989959348c9f4
Author: ...
Date: Mon Sep 1 17:21:40 2014 +0200
commit c
diff --git a/a b/a
index 422c2b7..de98044 100644
--- a/a
+++ b/a
@@ -1,2 +1,3 @@
a
b
+c
diff --git a/b b/b
index 6178079..9ddeb5c 100644
--- a/b
+++ b/b
@@ -1 +1,2 @@
b
+c
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
$ git diff b..d --
diff --git a/a b/a
index 422c2b7..d68dd40 100644
--- a/a
+++ b/a
@@ -1,2 +1,4 @@
a
b
+c
+d
diff --git a/b b/b
index 6178079..4bcfe98 100644
--- a/b
+++ b/b
@@ -1 +1 @@
-b
+d
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
$ git log -p d..b --
$ git show d..b --
$ git diff d..b --
diff --git a/a b/a
index d68dd40..422c2b7 100644
--- a/a
+++ b/a
@@ -1,4 +1,2 @@
a
b
-c
-d
diff --git a/b b/b
index 4bcfe98..6178079 100644
--- a/b
+++ b/b
@@ -1 +1 @@
-d
+b
diff --git a/c b/c
deleted file mode 100644
index f2ad6c7..0000000
--- a/c
+++ /dev/null
@@ -1 +0,0 @@
-c
$ git log -p b...d --
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
commit 8abaaff681be0bcaa16c946feb2989959348c9f4
Author: ...
Date: Mon Sep 1 17:21:40 2014 +0200
commit c
diff --git a/a b/a
index 422c2b7..de98044 100644
--- a/a
+++ b/a
@@ -1,2 +1,3 @@
a
b
+c
diff --git a/b b/b
index 6178079..9ddeb5c 100644
--- a/b
+++ b/b
@@ -1 +1,2 @@
b
+c
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
$ git show b...d --
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
commit 8abaaff681be0bcaa16c946feb2989959348c9f4
Author: ...
Date: Mon Sep 1 17:21:40 2014 +0200
commit c
diff --git a/a b/a
index 422c2b7..de98044 100644
--- a/a
+++ b/a
@@ -1,2 +1,3 @@
a
b
+c
diff --git a/b b/b
index 6178079..9ddeb5c 100644
--- a/b
+++ b/b
@@ -1 +1,2 @@
b
+c
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
$ git diff b...d --
diff --git a/a b/a
index 422c2b7..d68dd40 100644
--- a/a
+++ b/a
@@ -1,2 +1,4 @@
a
b
+c
+d
diff --git a/b b/b
index 6178079..4bcfe98 100644
--- a/b
+++ b/b
@@ -1 +1 @@
-b
+d
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
$ git log -p d...b --
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
commit 8abaaff681be0bcaa16c946feb2989959348c9f4
Author: ...
Date: Mon Sep 1 17:21:40 2014 +0200
commit c
diff --git a/a b/a
index 422c2b7..de98044 100644
--- a/a
+++ b/a
@@ -1,2 +1,3 @@
a
b
+c
diff --git a/b b/b
index 6178079..9ddeb5c 100644
--- a/b
+++ b/b
@@ -1 +1,2 @@
b
+c
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
$ git show d...b --
commit 08adc8512e63588e6f01533b2a0f762342521b05
Author: ...
Date: Mon Sep 1 17:22:06 2014 +0200
commit d
diff --git a/a b/a
index de98044..d68dd40 100644
--- a/a
+++ b/a
@@ -1,3 +1,4 @@
a
b
c
+d
diff --git a/b b/b
index 9ddeb5c..4bcfe98 100644
--- a/b
+++ b/b
@@ -1,2 +1 @@
-b
-c
+d
commit 8abaaff681be0bcaa16c946feb2989959348c9f4
Author: ...
Date: Mon Sep 1 17:21:40 2014 +0200
commit c
diff --git a/a b/a
index 422c2b7..de98044 100644
--- a/a
+++ b/a
@@ -1,2 +1,3 @@
a
b
+c
diff --git a/b b/b
index 6178079..9ddeb5c 100644
--- a/b
+++ b/b
@@ -1 +1,2 @@
b
+c
diff --git a/c b/c
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/c
@@ -0,0 +1 @@
+c
$ git diff d...b --
$
_