简体   繁体   English

仅查看某些分支的git log(带合并)

[英]View git log (with merges) for only certain branches

I know how to view the logs only for specific branches with --first-parent , like this: 我知道如何仅使用--first-parent查看特定分支的日志,如下所示:

git log --oneline --graph --first-parent origin/master origin/topic1

The problem with this is that I don't see the merge relationships between only those branches specified (which is what I want). 这个问题是我没有看到指定的那些分支之间的合并关系(这就是我想要的)。 If I do this: 如果我这样做:

git log --oneline --graph origin/master origin/topic1

It will show all branches anyway, even though I've specified I only want to see two of them. 无论如何它会显示所有分支,即使我已经指定我只想看到其中的两个。

What I want is to be able to specify specific branches to view the logs of and see the merges between only those branches. 我想要的是能够指定特定的分支来查看日志, 看到只有那些分支之间的合并。 The reason why I need this is because there are tons of other long-lived branches that cause the graph to get huge and I have to scroll several pages to find branch relationships. 我需要这个的原因是因为有很多其他长寿命的分支导致图形变大,我必须滚动几个页面才能找到分支关系。 I need a way to filter them out. 我需要一种方法来过滤掉它们。

Is this possible? 这可能吗?

EDIT 编辑

Here are my actual aliases: 这是我的实际别名:

short-log-base = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset)%x09%C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset) %C(dim white)%an%C(reset) - %C(white)%s%C(reset)'
lgs = !git short-log-base --first-parent

I do the following: 我做以下事情:

git lgs topic1 master

I realize passing in two branches will show the commits between those two, what I really want it to do is show me just those two branches plus any relationships between them. 我意识到传入两个分支将显示这两者之间的提交,我真正希望它做的是向我展示这两个分支以及它们之间的任何关系。 All other ancestors should be ignored and not shown. 所有其他祖先都应该被忽略而不显示。

When I run the command above, I am not seeing the graph draw lines between commits in those two branches where merge commits have occurred. 当我运行上面的命令时,我没有看到在发生合并提交的那两个分支中的提交之间的图形绘制线。

Here is just a small sample of my nightmare log graph (a snippet from the middle of it): 这里只是我的噩梦日志图的一小部分示例(中间的一个片段):

| | | | | | | | | | | | | | | | | * 431ce45     (5 months ago)
| | | | | | | | | | | | | | | | | * 14a0211     (6 months ago)
| | | | | | | | | | | | | | | | | * 0afde13     (8 months ago)
| | | | | | | | | | | | | | | | | * 88872ab     (3 weeks ago)
| |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|/
|/| | | | | | | | | | | | | | | |
* | | | | | | | | | | | | | | | | f8f9efd       (3 weeks ago)
* | | | | | | | | | | | | | | | | a65759b       (3 weeks ago)
* | | | | | | | | | | | | | | | | 6814d25       (3 weeks ago)
* | | | | | | | | | | | | | | | | ca242b7       (3 weeks ago)
* | | | | | | | | | | | | | | | | d29f84c       (3 weeks ago)
* | | | | | | | | | | | | | | | | 3e91342       (3 weeks ago)
* | | | | | | | | | | | | | | | | 5b23641       (3 weeks ago)
* | | | | | | | | | | | | | | | | 0e5e598       (3 weeks ago)
* | | | | | | | | | | | | | | | | f40e924       (3 weeks ago)
* | | | | | | | | | | | | | | | | 3614c05       (3 weeks ago)
| | | | | | | | | | | | | | | | | * b0b8f66     (3 weeks ago)
| | | | | | | | | | | | | | | | | * 5b9a183     (3 weeks ago)
| | | | | | | | | | | | | | | | | * 591af91     (3 weeks ago)
| | | | | | | | | | | | | | | | | * a1e6896     (3 weeks ago)
| | | | | | | | | | | | | | | | | * 9e12dc7     (3 weeks ago)
| | | | | | | | | | | | | | | | | * e7d4203     (3 weeks ago)
| | | | | | | | | | | | | | | | | * 5286952     (3 weeks ago)
| | | | | | | | | | | | | | | | | * a4e52b6     (4 weeks ago)
| | | | | | | | | | | | | | | | | * d1da806     (4 weeks ago)
| | | | | | | | | | | | | | | | | * 76b2174     (4 weeks ago)
| | | | | | | | | | | | | | | | | * 48b0687     (4 weeks ago)

I simply have NO idea why so many branches are being shown when as far as I'm concerned, I only want to see the graph between two branches. 我根本不知道为什么这么多分支被展示出来,就我而言,我只想看到两个分支之间的图形。 If getting this to work means limiting the length of the history, then by all means please let me know how I can do that. 如果让这个工作起来意味着限制历史的长度,那么请通过各种方式告诉我如何做到这一点。

You're not seeing "extra" branches 你没有看到“额外”的分支机构

The only reason why you're seeing additional branches is because those branches are ancestors of the branches that you specified on the command line. 您看到其他分支的唯一原因是因为这些分支您在命令行中指定的分支的祖先 To demonstrate, this is what my log looks like: 为了演示,这就是我的日志的样子:

$ git log --oneline --graph --decorate master temp -14
* 458e836 (HEAD, master) Add narf.txt   <===== Here is master
*   03bbab7 Merge branch 'bar'
|\
| * a765ecc (bar) Add quack.txt         <===== Here is bar
| * 80efc7c Add moo.txt
* | b1bc4f1 Add junk
|/
| * acb480b (temp) Add stuff after merge commit <===== Here is temp
| *   1e4b626 Merge branch 'foo' into temp
| |\
| | * 06c40a1 (foo) Add even more junk          <===== Here is foo
| | * ea3ea46 Add foo.txt
| |/
| * e918c72 Add derp.txt
| * f1a74d8 Add lol.txt
| * c244486 Add foo.txt
|/
* 7c61796 Fix OS X Bash `workdir` alias for new terminal tabs

Notice that even though I only specified master and temp on the command line, bar and foo are also shown, because they're ancestors of the other branches, and thus part of their history. 请注意,即使我只在命令行中指定了mastertemp ,也会显示barfoo ,因为它们是其他分支的祖先,因此也是其历史的一部分。

You probably don't want to use --no-merges for this... 你可能不想使用--no-merges ...

Additionally, I don't recommend that you use --no-merges to try to visualize your branches, because you can sometimes unintentionally leave out important information about when a merge between branches occurs with that flag. 此外,我不建议您使用--no-merges来尝试可视化您的分支,因为您有时可能会无意中遗漏有关何时使用该标志进行分支之间的合并的重要信息。 To demonstrate, this is what happens to my graph shown above when I use --no-merges : 为了演示,当我使用--no-merges时,这就是我上面显示的图形:

$ git log --oneline --graph --decorate --no-merges master temp -11
* 458e836 (HEAD, master) Add narf.txt  <===== Here is master
* a765ecc (bar) Add quack.txt          <===== Here is bar
* 80efc7c Add moo.txt
| * b1bc4f1 Add junk                   <===== Which branch does this belong to?
|/
| * acb480b (temp) Add stuff after merge commit  <===== Here is temp
| * 06c40a1 (foo) Add even more junk             <===== Here is foo
| * ea3ea46 Add foo.txt
| * e918c72 Add derp.txt
| * f1a74d8 Add lol.txt
| * c244486 Add foo.txt
|/
* 7c61796 Fix OS X Bash `workdir` alias for new terminal tabs

Notice that you now can't tell that the commit b1bc4f1 Add junk is an ancestor of 458e836 Add narf.txt . 请注意,您现在无法判断提交b1bc4f1 Add junk458e836 Add narf.txt的祖先458e836 Add narf.txt It looks as if b1bc4f1 Add junk isn't a part of master , when in fact it is. 看起来好像b1bc4f1 Add junk不是master的一部分,实际上它是。

Prefer --first-parent instead 首选--first-parent

If you want to simplify your branch history visualization, I recommend that you use the --first-parent flag instead: 如果您想简化分支历史可视化,我建议您使用--first-parent标志:

git log --oneline --graph --decorate --first-parent origin/master origin/topic1

This is what my graph log looks like using that instead of --no-merges : 这是我的图形日志使用它而不是--no-merges

$ git log --oneline --graph --decorate --first-parent master temp -9
* 458e836 (HEAD, master) Add narf.txt  <===== Here is master
* 03bbab7 Merge branch 'bar'
* b1bc4f1 Add junk
| * acb480b (temp) Add stuff after merge commit  <===== Here is temp
| * 1e4b626 Merge branch 'foo' into temp
| * e918c72 Add derp.txt
| * f1a74d8 Add lol.txt
| * c244486 Add foo.txt
|/
* 7c61796 Fix OS X Bash `workdir` alias for new terminal tabs

This actually accurately represents the final history of all the branches, while also simplifying the graph by hiding the intermediate commits. 这实际上准确地表示了所有分支的最终历史记录,同时还通过隐藏中间提交来简化图形。

Try git show-branch <list of branches> . 试试git show-branch <list of branches>

This will just show those branches as far back as their merge point. 这将只显示那些分支,直到它们的合并点。 It's mentioned in the "Everyday GIT With 20 Commands Or So" guide. 它在“每日GIT有20个命令或所以”指南中提到。

The example in the man page shows three branches: the first lines up to the '---' are the branches, showing which column they will be marked on; 手册页中的示例显示了三个分支:直到'---'的第一行是分支,显示了它们将被标记在哪一列; then the relevant commits in the order you gave in the options with a mark as to which branch that commit is contained in. 然后按照您在选项中给出的顺序进行相关提交,并在其中包含关于提交的分支的标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM