[英]View git log (with merges) for only certain branches
我知道如何仅使用--first-parent
查看特定分支的日志,如下所示:
git log --oneline --graph --first-parent origin/master origin/topic1
这个问题是我没有看到指定的那些分支之间的合并关系(这就是我想要的)。 如果我这样做:
git log --oneline --graph origin/master origin/topic1
无论如何它会显示所有分支,即使我已经指定我只想看到其中的两个。
我想要的是能够指定特定的分支来查看日志, 并看到只有那些分支之间的合并。 我需要这个的原因是因为有很多其他长寿命的分支导致图形变大,我必须滚动几个页面才能找到分支关系。 我需要一种方法来过滤掉它们。
这可能吗?
这是我的实际别名:
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
我做以下事情:
git lgs topic1 master
我意识到传入两个分支将显示这两者之间的提交,我真正希望它做的是向我展示这两个分支以及它们之间的任何关系。 所有其他祖先都应该被忽略而不显示。
当我运行上面的命令时,我没有看到在发生合并提交的那两个分支中的提交之间的图形绘制线。
这里只是我的噩梦日志图的一小部分示例(中间的一个片段):
| | | | | | | | | | | | | | | | | * 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)
我根本不知道为什么这么多分支被展示出来,就我而言,我只想看到两个分支之间的图形。 如果让这个工作起来意味着限制历史的长度,那么请通过各种方式告诉我如何做到这一点。
您看到其他分支的唯一原因是因为这些分支是您在命令行中指定的分支的祖先 。 为了演示,这就是我的日志的样子:
$ 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
请注意,即使我只在命令行中指定了master
和temp
,也会显示bar
和foo
,因为它们是其他分支的祖先,因此也是其历史的一部分。
--no-merges
... 此外,我不建议您使用--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
请注意,您现在无法判断提交b1bc4f1 Add junk
是458e836 Add narf.txt
的祖先458e836 Add narf.txt
。 看起来好像b1bc4f1 Add junk
不是master
的一部分,实际上它是。
--first-parent
如果您想简化分支历史可视化,我建议您使用--first-parent
标志:
git log --oneline --graph --decorate --first-parent origin/master origin/topic1
这是我的图形日志使用它而不是--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
这实际上准确地表示了所有分支的最终历史记录,同时还通过隐藏中间提交来简化图形。
试试git show-branch <list of branches>
。
这将只显示那些分支,直到它们的合并点。 它在“每日GIT有20个命令或所以”指南中提到。
手册页中的示例显示了三个分支:直到'---'的第一行是分支,显示了它们将被标记在哪一列; 然后按照您在选项中给出的顺序进行相关提交,并在其中包含关于提交的分支的标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.