git log --branches 工作吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5316802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does git log --branches work?
提问by cflewis
I can't seem to get git log --branches
to correctly filter its output. It seems as if Git ignores it.
我似乎无法git log --branches
正确过滤其输出。似乎 Git 忽略了它。
For example, the head of git log --graph --all --decorate
, prints:
例如, , 的头部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
|
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:
假设我想通过过滤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 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?
Git似乎没有过滤。是否--branches
与其他参数一起传递似乎没有任何区别。我的 Git 版本是git version 1.7.4.1
. 有谁知道如何成功使用这个命令?
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.
编辑:我想要做的就是获取一个或另一个分支的日志,而不必先进行结帐。
采纳答案by Adam Spiers
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?
首先,(另一个)Adam 是对的,使用它没有意义--all
:如果您只想看到一个分支,如您的问题所述,为什么要要求所有分支?
Secondly, as already stated in comments to other answers, you don't need --branches
; just do git log mybranch
.
其次,正如其他答案的评论中所述,您不需要--branches
; 就做git log mybranch
。
Thirdly, I can explain why git log --branches=mybranch
doesn't work. The git-log(1)
man pagesays:
第三,我可以解释为什么git log --branches=mybranch
不起作用。该git-log(1)
手册页说:
--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
最后一句话是这里的关键。如果<pattern>
是,mybranch
则没有通配符,因此git-log
将其解释为您已键入
git log --branches=mybranch/*
which only matches references under $repo/.git/refs/heads/mybranch/*
, i.e. branches which begin with mybranch/
.
只匹配 下的引用$repo/.git/refs/heads/mybranch/*
,即以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
回答by Adam Dymitruk
Because you specified --all
, you override any branch specifications you made.
因为您指定了--all
,所以您覆盖了您所做的任何分支规范。
回答by sholte
Let's say your history looked like this
假设你的历史看起来像这样
d -- e [refs/tags/release1]
/
a -- b -- c [refs/heads/master]
\
f -- g [refs/heads/dev1]
\
h [refs/heads/dev2]
If you do git log --branches
it's the same git log master dev1 dev2
, so you'll see commits a,b,c,f,g and h. If you did git log release1 --branches=dev*
it's the same as git log release1 dev1 dev2
. You'll see a,d,e,b,f,g, and h, but not c.
如果你这样做git log --branches
是一样的git log master dev1 dev2
,所以你会看到提交 a,b,c,f,g 和 h。如果你这样做了,git log release1 --branches=dev*
它与git log release1 dev1 dev2
. 您会看到 a、d、e、b、f、g 和 h,但不会看到 c。
回答by pestrella
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.
有谁知道如何成功使用这个命令?
编辑:我想要做的就是获取一个或另一个分支的日志,而不必先进行结帐。
In order to visualise the graph of commits on all branches and remotes do this:
为了可视化所有分支和远程的提交图,请执行以下操作:
$ git log --graph --branches=* --remotes=* --decorate
Use this with other git-log
options to control verbosity, e.g. --oneline
, --name-status
, etc.
使用此与其他git-log
选项来控制详细程度,例如--oneline
,--name-status
等等。
You may have to fetch remote changes first in order to see them. You can fetch all remote changes without applying them to your current branch(es) like this:
您可能必须先获取远程更改才能看到它们。您可以获取所有远程更改而不将它们应用到您当前的分支,如下所示:
$ git fetch --all
回答by Shaun Luttin
Explanation of --branches
的解释 --branches
git log <commit>
lists all commits that are reachable from any <commit>
that you list on the command line.
git log <commit>
列出可从<commit>
您在命令行中列出的任何提交访问的所有提交。
--all
does the same but pretends that you listed all the refs inrefs/
.--branches[=<pattern>]
does the same but pretends that you listed all the refs inrefs/heads
. It also allows you to limit with a glob pattern. As a gotcha, if your glob pattern lacks?
,,
or[
, then an/
at the end is implied.
--all
做同样的事情,但假装你在refs/
.--branches[=<pattern>]
做同样的事情,但假装你在refs/heads
. 它还允许您使用 glob 模式进行限制。作为一个陷阱,如果您的 glob 模式缺少?
,,
或[
,则/
暗示末尾为 。
Examples
例子
git log topic1 topic2 topic3
git log topic1 topic2 topic3
means list all the commits reachable from topic1
, topic2
, or topic3
.
是指列出的所有提交到达从topic1
,topic2
或topic3
。
git log -all
git log -all
means list all the commits that are reachable from any of the refs that are output from git show-ref
.
表示列出从git show-ref
.
git log --branches="topic*"
git log --branches="topic*"
means list all the commits that are reachable from from any branch that starts with the prefix topic
.
表示列出从以前缀开头的任何分支可访问的所有提交topic
。
Sources
来源
https://schacon.github.io/git/git-log.html
https://schacon.github.io/git/git-log.html