2012-03-15 39 views
38

有沒有辦法與git log或其他命令一起查看分支創建後添加的提交?顯示自創建分支以來的提交

usage: git log [<options>] [<since>..<until>] [[--] <path>...] 
    or: git show [options] <object>... 

    --quiet    suppress diff output 
    --source    show source 
    --decorate[=...]  decorate options 
+1

相關:【如何獲得Git中的一個分支的變化(http://stackoverflow.com/questions/53569/how- git) – 2012-03-15 18:09:32

回答

3

是它可能與主分支來比較你的 「新」 分支(通常稱爲 「主」):

git log master..<your_branch_name> 

當然,更換<your_branch_name>

+4

這隻顯示自從您最後一次從主服務器上拉出來的提交,或者反之亦然,這與自從創建分支以來顯示提交不同。 – spiffytech 2012-11-20 20:48:50

+0

也適用於git diff master..your_branch_name – jspooner 2014-05-07 17:40:45

39

用三個階段來引用承諾將上述第二分支從第一分叉,或在這種情況下,您的分支從主分歧:

git log master...<your_branch_name> 

確保使用時期這種情況。

側面說明:您也可以撇下分支名,與git的自動引用頭指針在這種情況下,例如:

git log master... 

相當於我前面的例子。這可以在提交比較可用的任何地方工作。

+1

在我的情況下'git log master..'起作用。 – MKatleast3 2017-02-02 04:28:59

+1

'git log master ...'不適合我,只有'git log master..'工作。注意兩個點而不是三個 – NecipAllef 2018-02-08 14:15:20

+0

很高興它爲你工作。 Double for顯然是正確的語法。但要小心,點是重要的。請參閱Alan Thompson的答案,詳細解釋雙點和三點符號之間的區別。 – 2018-02-09 17:56:44

29

完整文檔是在這裏: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 loggit 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)的前端的DIFF到尖端myBranch(Z)的。三點版本顯示了從myBranch(即B)到myBranch(Z)尖端的差異。

+0

如果你想做'git log --oneline myBranch..master',那會給你'D'還是'C'? – MiniGod 2015-12-01 10:59:41

+1

upvote描述..和...之間的區別並提供示例。真棒回答! – 2016-01-20 17:18:18

8

如果您對您所創建的分支:

git log master.. 
相關問題