git:需要解析提交消息以查找模式并存储在列表中

发布于 2024-12-20 11:08:15 字数 190 浏览 5 评论 0原文

我的所有 git 提交消息都以 SOME_NUMBER 开头

  refs #SOME_NUMBER

,其中 SOME_NUMBER 是从 1 开始的数字。我想解析所有提交消息 我的工作分支,将所有 SOME_NUMBER 存储在列表中,删除重复项,然后保存到文件。不太确定从哪里开始......

all of my git commit messages start with

  refs #SOME_NUMBER

where SOME_NUMBER is a number from 1 up. I would like to parse all commmit messages on
my working branch, store all of the SOME_NUMBERs in a list, remove duplicates, and save to file. Not really sure where to start....

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

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

发布评论

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

评论(1

浅忆 2024-12-27 11:08:15

您可以使用此 shell 单行代码轻松完成此操作:

$ git log --format=%s | cut -f 2 -d ' ' | sed 's/#\(.*\)/\1/' | sort -n | uniq > refs.txt

说明:

  1. git log --format=%s 显示每个提交消息的第一行
  2. cut -f 2 -d ' '< /code> 用空格分割该行,并打印(#SOME_NUMBER 部分)的第二部分
  3. sed 's/#\(.*\)/\1/'< /code> 删除数字符号number
  4. sort 按数字升序对条目进行排序
  5. uniq 确保每个数字仅打印一次
  6. > refs.txt 将输出打印到名为 refs.txt 的文件中。

You can do that pretty easily with this shell one-liner:

$ git log --format=%s | cut -f 2 -d ' ' | sed 's/#\(.*\)/\1/' | sort -n | uniq > refs.txt

Explanation:

  1. git log --format=%s displays the first line of every commit message
  2. cut -f 2 -d ' ' splits the line by a space, and prints the second part of the (the #SOME_NUMBER portion)
  3. sed 's/#\(.*\)/\1/' removes the number sign from the number
  4. sort sorts the entries in ascending numerical order
  5. uniq ensures that each number is only printed once
  6. > refs.txt prints the output to a file called refs.txt.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文