2011-03-15 108 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