简体   繁体   English

在 git log 中只显示标记的提交

[英]Show only tagged commits in git log

I'm looking for a way to show a git log, ordered by commits, showing their dates, and also, showing only commits which have tags.我正在寻找一种方法来显示 git 日志,按提交排序,显示日期,并且只显示带有标签的提交。

Our webhost has an automated deploy system, and when a particular commit is pushed to production, it gets a certain tag on it.我们的网络主机有一个自动部署系统,当一个特定的提交被推送到生产时,它会在上面得到一个特定的标签。 I am troubleshooting an issue, and I want to look at only those commits that have been on production.我正在解决一个问题,我只想查看那些已经在生产中的提交。

I was able to make a git alias, which I call nanolog , like this:我能够创建一个 git 别名,我称之为nanolog ,如下所示:

nanolog = log --date-order --date=format:'%Y-%m-%d %H:%M:%S' --format='%C(yellow)%cd%Creset  %h  \"%s\"  %Cred%cn %Cgreen(%cr)'

which gives me a log looking like this:这给了我一个看起来像这样的日志:

2019-06-17 23:39:43  13f7e5f89  "Merge branch 'live-config' into int"  Webhost (3 weeks ago)
2019-06-17 23:24:20  32b6141dc  "Merge branch 'live-config' into int"  User Name (3 weeks ago)

I've looked at the documentation for git log , and in the section about --format , which is what I used to specify which information is displayed in my nanolog alias, I did not find any way to display tags.我查看git log的文档,在关于--format的部分中,这是我用来指定在我的nanolog别名中显示哪些信息的部分,我没有找到任何显示标签的方法。 I looked at the pretty formats documentation , and likewise did not find a way to specify tag information.我查看了漂亮的格式文档,同样没有找到指定标签信息的方法。

In the stock git log , you see tags next to the commit hash:在股票git log ,您会在提交哈希旁边看到标签:

commit d1d59f2fe151d1eb240b453e6efe76e4dfe13a93 (tag: webhost_test_198, tag: webhost_live_114, origin/06-24, 06-24)
Merge: 13f7e5f89 143b58189
Author: Webhost <webhost@webhost.com>
Date:   Fri Jun 21 20:25:24 2019 +0000

    Merged int into master

It's fairly laborious and somewhat error-prone to scroll through the stock git log , which does include tags information, along with all the other untagged commits.滚动浏览股票git log相当费力,而且有些容易出错,其中包括标签信息,以及所有其他未标记的提交。 How can I get a brief log that shows only commits with tags?如何获得仅显示带有标签的提交的简短日志?

Ideally I would like something like this:理想情况下,我想要这样的东西:

2019-06-17 23:39:43  13f7e5f89 (tag: webhost_test_198, tag: webhost_live_114, origin/06-24, 06-24) "Merge branch 'live-config' into int"  Webhost (3 weeks ago)
2019-06-03 23:24:20  32b6141dc (tag: webhost_test_197, tag: webhost_live_113,)  "Merge branch 'live-config' into int"  User Name (5 weeks ago)

Let's start from a simple --oneline output on a mock repo and only last three commits让我们从模拟存储库上的简单--oneline输出开始,并且只有最后三个提交

git log --oneline -3

4c37e97 fixed a bug in sub-feature F1
d9c4599 added sub-feature F1
06014cb changed part XYZ

Now if we add decorations (references pointing to commits, namely tags and branches) with the --decorate flag :现在,如果我们使用--decorate标志添加装饰(指向提交的引用,即标签和分支):

git log --oneline --decorate -3

4c37e97 (HEAD -> feature/abc) fixed a bug in sub-feature F1
d9c4599 added sub-feature F1
06014cb (tag: release/1.22) changed part XYZ

And at this point you can also add the --simplify-by-decoration flag to filter out commits not referenced by any tag/branch此时你还可以添加--simplify-by-decoration标志来过滤掉没有被任何标签/分支引用的提交

git log --oneline --decorate --simplify-by-decoration -3

4c37e97 (HEAD -> feature/abc) fixed a bug in sub-feature F1
06014cb (tag: release/1.22) changed part XYZ
eec8aad (master) some older change

But in your case with a specific format, you have the %d to this effect.但是在您使用特定格式的情况下,您可以使用%d来实现这种效果。

If we modify your nanolog , which in my example outputs the following :如果我们修改您的nanolog ,在我的示例中输出以下内容:

git nanolog -3

2019-07-08 19:19:46  4c37e97  "fixed a bug in sub-feature F1"  Romain (69 seconds ago)
2019-07-08 19:19:11  d9c4599  "added sub-feature F1"  Romain (2 minutes ago)
2019-07-08 19:18:26  06014cb  "changed part XYZ"  Romain (2 minutes ago)

into this one进入这个

    nanolog2 = log --date-order --date=format:'%Y-%m-%d %H:%M:%S' --format='%C(yellow)%cd%Creset  %h  \"%d %s\"  %Cred%cn %Cgreen(%cr)'

...we'll obtain ...我们会得到

git nanolog2 -3

2019-07-08 19:19:46  4c37e97  " (HEAD -> feature/abc) fixed a bug in sub-feature F1"  Romain (12 minutes ago)
2019-07-08 19:19:11  d9c4599  " added sub-feature F1"  Romain (13 minutes ago)
2019-07-08 19:18:26  06014cb  " (tag: release/1.22) changed part XYZ"  Romain (14 minutes ago)

Finally, yes, you can pipe this to a grep "(tag:" or maybe just grep tag to filter out commits with only branches but no tags.最后,是的,您可以将其传递给grep "(tag:"或者只是grep tag来过滤掉只有分支但没有标记的提交。

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

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