git:需要解析提交消息以查找模式并存储在列表中
我的所有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此 shell 单行代码轻松完成此操作:
说明:
git log --format=%s
显示每个提交消息的第一行cut -f 2 -d ' '< /code> 用空格分割该行,并打印(
#SOME_NUMBER
部分)的第二部分sed 's/#\(.*\)/\1/'< /code> 删除数字符号number
sort
按数字升序对条目进行排序uniq
确保每个数字仅打印一次> refs.txt
将输出打印到名为refs.txt
的文件中。You can do that pretty easily with this shell one-liner:
Explanation:
git log --format=%s
displays the first line of every commit messagecut -f 2 -d ' '
splits the line by a space, and prints the second part of the (the#SOME_NUMBER
portion)sed 's/#\(.*\)/\1/'
removes the number sign from the numbersort
sorts the entries in ascending numerical orderuniq
ensures that each number is only printed once> refs.txt
prints the output to a file calledrefs.txt
.