2011-03-15 52 views
24

我似乎無法得到git log --branches正確過濾其輸出。好像Git忽略它。git log - 分支是否工作?

例如,git log --graph --all --decorate頭,打印:

* commit 3ae0d17538f787bdde68f37f6644ffe9652d8dc1 (HEAD, feature/branch-ignore) 
| Author: Chris Lewis <[email protected]> 
| Date: Mon Mar 14 17:39:56 2011 -0700 
| 
|  Ignore merge commits, as they're going to be duplicating events 
| 
* commit 770534e9d77acb03eaf842440c879aec1c5b5500 
| Author: Chris Lewis <[email protected]> 
| Date: Tue Mar 8 14:39:40 2011 -0800 
| 
|  Removed another remote branch check 
| 

比方說,我想通過master過濾,這應該意味着這些提交被忽略。 git log --graph --all --decorate --branches=master的頭也是:

* commit 3ae0d17538f787bdde68f37f6644ffe9652d8dc1 (HEAD, feature/branch-ignore) 
| Author: Chris Lewis <[email protected]> 
| Date: Mon Mar 14 17:39:56 2011 -0700 
| 
|  Ignore merge commits, as they're going to be duplicating events 
| 
* commit 770534e9d77acb03eaf842440c879aec1c5b5500 
| Author: Chris Lewis <[email protected]> 
| Date: Tue Mar 8 14:39:40 2011 -0800 
| 
|  Removed another remote branch check 
| 

Git似乎沒有過濾。 --branches是否與其他參數一起傳遞似乎沒有什麼區別。我的Git版本是git version 1.7.4.1。有誰知道如何成功使用這個命令?

編輯:我希望能夠做的就是獲得一個分支或另一個分支的日誌,而不必先結賬。

+2

有趣的問題。到目前爲止,下面的評論都沒有提到 - 分支應該做什麼或者它應該如何工作。 – 2012-05-15 01:52:47

+1

我已經添加了一個答案,現在解釋了爲什麼它確實工作正常,即使它看起來不是。 – 2015-02-05 00:18:38

回答

11

首先,(其他)亞當是正確的,那是沒有意義的使用--all爲:如果你只想看到像你的問題狀態的一個分支,爲什麼要求所有分支?其次,正如其他答案的評論中所述,你不需要--branches;只是做git log mybranch

第三,我可以解釋爲什麼git log --branches=mybranch不起作用。 git-log(1) man page說:

--branches[=<pattern>] 
    Pretend as if all the refs in refs/heads are listed on 
    the command line as <commit>. If <pattern> is given, 
    limit branches to ones matching given shell glob. If 
    pattern lacks ?, *, or [, /* at the end is implied. 

最後一句話是這裏的關鍵點。如果<pattern>只是mybranch那麼沒有通配符的字符,所以git-log其解釋爲,如果你鍵入

git log --branches=mybranch/* 

只匹配$repo/.git/refs/heads/mybranch/*下引用,即分行與mybranch/開始。

有一個骯髒的黑客,防止/*被假定:

git log --branches=[m]ybranch 

,但我想不出什麼好理由,你爲什麼會想這樣做,而不是隻是打字

git log mybranch 
+1

然後它只有一個分支(git log mybranch)或所有分支。如果你想要,說兩個分支。 - 人們會認爲,分支將是實現這一目標的方式。什麼是? – Emmel 2016-10-06 18:34:26

+1

@Emmel'git log branch1 branch2' – 2016-10-07 12:10:21

+0

降低評分的人能否爲我們提供解釋原因的評論? – 2016-10-11 13:32:35

12

因爲您指定了--all,所以您會覆蓋您制定的所有分支規範。

+3

缺少警告似乎對我來說是一個可用性錯誤。 – nes1983 2011-03-15 19:54:49

+2

正如我在問題中提到的那樣,如果我使用其他標誌,它似乎沒有任何區別。 'git log --branches = master'給出相同的提交(顯然,格式不同)。它只是不工作。 – cflewis 2011-03-15 21:27:14

+3

@Lewisham:如果你只想要主人,請使用'git log master'。 – Cascabel 2011-03-15 22:40:11

2

比方說,你的歷史看起來像這樣

d -- e [refs/tags/release1] 
/
a -- b -- c [refs/heads/master] 
     \ 
     f -- g [refs/heads/dev1] 
     \ 
     h [refs/heads/dev2] 

如果你git log --branches這是相同的git log master dev1 dev2,所以你會看到一個承諾,B,C,F,G和H。如果你做了git log release1 --branches=dev*這與git log release1 dev1 dev2相同。你會看到a,d,e,b,f,g和h,但不是c。

3

有誰知道如何成功使用這個命令?

編輯:我希望能夠做的就是獲得一個分支或另一個分支的日誌,而不必先結賬。

爲了形象化所有分支上提交的圖形和遙控器這樣做:

$ git log --graph --branches=* --remotes=* --decorate 

使用此與其他git-log選項來控制冗長,例如--oneline,--name-status

您可能必須首先獲取遠程更改才能看到它們。您可以獲取所有遠程更改,但不這樣把它們應用到你當前分支(ES):

$ git fetch --all 
1

--branches

git log <commit>列出了從任何<commit>到達的所有提交解釋說你在命令行上列出。

  • --all不相同,但假裝你列出的所有裁判在refs/

  • --branches[=<pattern>]的確如此,但假裝列出了所有在refs/heads中的參考文獻。它也允許你限制一個glob模式。作爲一個問題,如果您的glob模式缺少?,,[,則隱含末尾的/

實例

git log topic1 topic2 topic3

指從topic1topic2,或topic3到達列表中的所有的提交。

git log -all

指列出所有來自任何來自git show-ref輸出裁判可達的提交。

git log --branches="topic*"

意味着列表中的所有那些從以前綴topic開始任何分支到達的提交。

來源

https://schacon.github.io/git/git-log.html

https://schacon.github.io/git/git-rev-list.html