标签之间的 Git 日志

发布于 2024-12-15 18:43:04 字数 400 浏览 1 评论 0原文

我正在尝试输出两个标记提交之间的日志。

mbell@cheetah [12:07:22] [/var/www/html/brone] [dev]
-> % git tag 
6.x-0.1
6.x-1.0-beta1
6.x-1.0-beta2
6.x-1.0-beta3
6.x-1.0-beta4
6.x-1.0-beta5
6.x-1.0-beta6
6.x-1.0-beta7
6.x-1.0-beta8
6.x-1.0-beta9

如果我这样做:

git log 6.x-1.0-beta8 6.x-1.0-beta9 > ~/gitlogbrone.txt

它输出自存储库启动以来的所有提交,这不是我想要的。我已经阅读了 git log 手册,但没有多大帮助。

I'm trying to output the log between two tagged commits.

mbell@cheetah [12:07:22] [/var/www/html/brone] [dev]
-> % git tag 
6.x-0.1
6.x-1.0-beta1
6.x-1.0-beta2
6.x-1.0-beta3
6.x-1.0-beta4
6.x-1.0-beta5
6.x-1.0-beta6
6.x-1.0-beta7
6.x-1.0-beta8
6.x-1.0-beta9

If I then do:

git log 6.x-1.0-beta8 6.x-1.0-beta9 > ~/gitlogbrone.txt

It outputs all the commits since the start of the repo which isn't what I want. I've read through the git log manual but it's not helping much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

这样的小城市 2024-12-22 18:43:04

您需要一个省略号来指示范围。尝试git log tag1..tag2

You need an ellipsis to indicate a range. Try git log tag1..tag2.

冬天旳寂寞 2024-12-22 18:43:04

对于那些有兴趣生成发行说明文件并想要一个可读且易于修改的脚本的人来说,对 @Yurii 和 @wilmol 的答案进行了扩展。

export VERSION=$(git tag --sort=-committerdate | head -1)
export PREVIOUS_VERSION=$(git tag --sort=-committerdate | head -2 | awk '{split($0, tags, "\n")} END {print tags[1]}')
export CHANGES=$(git log --pretty="- %s" $VERSION...$PREVIOUS_VERSION)
printf "#

An expansion on the answers from @Yurii and @wilmol for those interested in generating a release notes file and wanting a script that is readable and easily modified.

export VERSION=$(git tag --sort=-committerdate | head -1)
export PREVIOUS_VERSION=$(git tag --sort=-committerdate | head -2 | awk '{split($0, tags, "\n")} END {print tags[1]}')
export CHANGES=$(git log --pretty="- %s" $VERSION...$PREVIOUS_VERSION)
printf "# ???? Release notes (\`$VERSION\`)\n\n## Changes\n$CHANGES\n\n## Metadata\n\`\`\`\nThis version -------- $VERSION\nPrevious version ---- $PREVIOUS_VERSION\nTotal commits ------- $(echo "$CHANGES" | wc -l)\n\`\`\`\n" > release_notes.md

The above script generates a markdown file at release_notes.md that looks like this:


???? Release notes (14.2)

Changes

  • ABCDEFGHIJKLMNOP
  • ABCDEFGHIJKLMNOP
  • ABCDEFGHIJKLMNOP
  • ABCDEFGHIJKLMNOP
  • ABCDEFGHIJKLMNOP

Metadata

This version -------- 14.2
Previous version ---- 14.1
Total commits ------- 5

I like this approach for a few reasons:

  • If there is a tag between the two tags I'm interested in, I can manually set $VERSION and $PREVIOUS_VERSION before running the last two lines.

  • With a few tweaks, I can sort, filter, and modify $CHANGES to meet my specific needs.

哑剧 2024-12-22 18:43:04

我用它来获取最后两个标签之间的提交:

git log --pretty=format:%s `git tag --sort=-committerdate | head -1`...`git tag --sort=-committerdate | head -2 | awk '{split($0, tags, "\n")} END {print tags[1]}'` > change_log.txt

I use this to get the commits between the last 2 tags:

git log --pretty=format:%s `git tag --sort=-committerdate | head -1`...`git tag --sort=-committerdate | head -2 | awk '{split($0, tags, "\n")} END {print tags[1]}'` > change_log.txt
旧梦荧光笔 2024-12-22 18:43:04

感谢 @Noufal Ibrahim 的回答。

我正在提交一个文件并创建一个新标签。但在此之前,我需要列出并格式化最后一个标签创建后的所有提交。这是我当时所做的:

$ git log <last_tag>..

注意末尾的双点 (..)

Thanks to @Noufal Ibrahim for his answer.

I was committing a file and creating a new tag. But before doing that, my need was to list and format all of the commits after the last tag created. Here is what I did that time:

$ git log <last_tag>..

Notice double dot (..) at the end

只为守护你 2024-12-22 18:43:04

@wilmol 的一个稍微优化的解决方案,

git log --pretty=oneline `git tag --sort=-committerdate | head -1`...`git tag --sort=-committerdate | head -2 | tail -1`

我更喜欢在版本注释的脚本中使用以下代码:

git log --pretty=oneline `git tag --sort=-committerdate | head -1`...`git tag --sort=-committerdate | head -2 | tail -1` |cut -d " " -f 2- |grep -v "Merge pull request"

这个代码给出了最后两个标签之间的清晰提交历史记录,没有 git has 和合并行。

A bit optimised solution from @wilmol

git log --pretty=oneline `git tag --sort=-committerdate | head -1`...`git tag --sort=-committerdate | head -2 | tail -1`

I prefer to use in scripts for the release notes the following code:

git log --pretty=oneline `git tag --sort=-committerdate | head -1`...`git tag --sort=-committerdate | head -2 | tail -1` |cut -d " " -f 2- |grep -v "Merge pull request"

This one give a clear commits history between two last tags without git has and merge lines.

感情废物 2024-12-22 18:43:04

我正在使用以下快捷方式

git log $(git tag |tail -1)..

I'm using the following shortcut

git log $(git tag |tail -1)..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文