git log - 分支是否工作? [英] Does git log --branches work?

查看:121
本文介绍了git log - 分支是否工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到 git log --branches 来正确地过滤它的输出。好像Git忽略它。



例如,的头部git log --graph --all --decorate

  * commit 3ae0d17538f787bdde68f37f6644ffe9652d8dc1(HEAD,feature / branch-ignore)
|作者:克里斯刘易斯< chris@chris.to>
|日期:星期一3月14日17:39:56 2011 -0700
|
|忽略合并提交,因为它们将复制事件
|
* commit 770534e9d77acb03eaf842440c879aec1c5b5500
|作者:克里斯刘易斯< chris@chris.to>
|日期:星期二3月8日14:39:40 2011 -0800
|
|删除了另一个远程分支检查
|

假设我想按照 master ,这应该意味着这些提交被忽略。 git log --graph --all --decorate --branches = master 的头部也是:

  * commit 3ae0d17538f787bdde68f37f6644ffe9652d8dc1(HEAD,feature / branch-ignore)
|作者:克里斯刘易斯< chris@chris.to>
|日期:星期一3月14日17:39:56 2011 -0700
|
|忽略合并提交,因为它们将复制事件
|
* commit 770534e9d77acb03eaf842440c879aec1c5b5500
|作者:克里斯刘易斯< chris@chris.to>
|日期:星期二3月8日14:39:40 2011 -0800
|
|删除了另一个远程分支检查
|

Git似乎没有被过滤。它与 - 分支是否与其他参数一起传递似乎没有任何区别。我的Git版本是 git版本1.7.4.1 。有没有人知道如何成功地使用这个命令?



编辑:我希望能够做的就是获取一个分支或另一个分支的日志,而不必做首先,(另一个)亚当是正确的,它没有意义使用 - all for this:如果你只想看到一个分支,比如你的问题状态,为什么要问所有的分支?

第二部分第二部分,如其他答案的评论中所述,您不需要 - 分支;只需做 git log mybranch



第三,我可以解释为什么 git log - branches = mybranch 不起作用。 git-log(1)手册页说:

   - 分支[=<模式>] 
假装所有参考refs / heads在
上列出,命令行为< commit> ;.如果< pattern>是给定的,
限制分支给与给定的shell glob相匹配的。如果
模式缺少?,*,或者最后的[,/ *是隐含的。

最后一句话是关键。如果< pattern> 只是 mybranch ,那么就没有通配符,所以 git -log 将其解释为您键入的内容

  git log --branches = mybranch / * 

它只与 $ repo / .git / refs / heads / mybranch / * ,即以 mybranch / 开头的分支。



肮脏的黑客来防止 / * 被假定:

  git log --branches = [m] ybranch 

但我想不出你有什么好的理由希望这样做而不是仅仅输入

  git log mybranch 


I can't seem to get git log --branches to correctly filter its output. It seems as if Git ignores it.

For example, the head of git log --graph --all --decorate, prints:

* commit 3ae0d17538f787bdde68f37f6644ffe9652d8dc1 (HEAD, feature/branch-ignore)
| Author: Chris Lewis <chris@chris.to>
| 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 <chris@chris.to>
| Date:   Tue Mar 8 14:39:40 2011 -0800
| 
|     Removed another remote branch check
| 

Let's say I want to filter by master, which should mean these commits are ignored. The head of git log --graph --all --decorate --branches=master, is also:

* commit 3ae0d17538f787bdde68f37f6644ffe9652d8dc1 (HEAD, feature/branch-ignore)
| Author: Chris Lewis <chris@chris.to>
| 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 <chris@chris.to>
| Date:   Tue Mar 8 14:39:40 2011 -0800
| 
|     Removed another remote branch check
|  

Git doesn't seem to be filtering. It doesn't seem to make any difference whether --branches is passed with other arguments or not. My Git version is git version 1.7.4.1. Does anyone know how to use this command successfully?

EDIT: All I want to be able to do is get the log of one branch or another, without having to do a checkout first.

解决方案

Firstly, (the other) Adam is right that it doesn't make sense to use --all for this: if you only want to see one branch like your question states, why ask for all branches?

Secondly, as already stated in comments to other answers, you don't need --branches; just do git log mybranch.

Thirdly, I can explain why git log --branches=mybranch doesn't work. The git-log(1) man page says:

--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.

The last sentence is the crucial point here. If the <pattern> is just mybranch then there is no globbing character, so git-log interprets it as if you'd typed

git log --branches=mybranch/*

which only matches references under $repo/.git/refs/heads/mybranch/*, i.e. branches which begin with mybranch/.

There is a dirty hack to prevent the /* from being assumed:

git log --branches=[m]ybranch

but I can't think of any good reason why you would want to do this rather than just typing

git log mybranch

这篇关于git log - 分支是否工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆