完整的文档在这里:https : //www.kernel.org/pub/software/scm/git/docs/gitrevisions.html
假设您有一个如下所示的仓库:
base - A - B - C - D (master)
\
\- X - Y - Z (myBranch)
验证回购状态:
> git checkout master
Already on 'master'
> git status ; git log --oneline
On branch master
nothing to commit, working directory clean
d9addce D
110a9ab C
5f3f8db B
0f26e69 A
e764ffa base
对于myBranch:
> git checkout myBranch
> git status ; git log --oneline
On branch myBranch
nothing to commit, working directory clean
3bc0d40 Z
917ac8d Y
3e65f72 X
5f3f8db B
0f26e69 A
e764ffa base
假设您在myBranch上,并且只希望更改SINCE master。使用两点式:
> git log --oneline master..myBranch
3bc0d40 Z
917ac8d Y
3e65f72 X
三点版本提供了从母版技巧到myBranch技巧的所有更改。但是,请注意,不包含公共提交B:
> git log --oneline master...myBranch
d9addce D
110a9ab C
3bc0d40 Z
917ac8d Y
3e65f72 X
请注意: git log
并且git diff
行为各不相同! 行为并不完全相反,但几乎是:
> git diff master..myBranch
diff --git a/rev.txt b/rev.txt
index 1784810..e900b1c 100644
--- a/rev.txt
+++ b/rev.txt
@@ -1 +1 @@
-D
+Z
> git diff master...myBranch
diff --git a/rev.txt b/rev.txt
index 223b783..e900b1c 100644
--- a/rev.txt
+++ b/rev.txt
@@ -1 +1 @@
-B
+Z
因此,两点版本显示了从母版的尖端(即D)到myBranch(Z)的尖端的差异。三点版本显示从myBranch的底部(即B)到myBranch的尖端(Z)的差异。