【问题标题】:What command can I use to extract fields from this Git svn mirror commit messages?我可以使用什么命令从这个 Git svn mirror 提交消息中提取字段?
【发布时间】:2015-03-23 18:52:56
【问题描述】:

下面的文本是来自实时 Subversion 的 Git 镜像的提交消息,所有提交消息都采用这种样式。是否有一些命令可以用来以类似表格的方式提取信息,每次提交一行。

commit c49a28ae19400fd14d60cd42fda9b3f527a5ee80
Author: martin <martin@4005530d-fff6-0310-9dd1-cebe43e6787f>
Date:   Mon Mar 23 00:45:30 2015 +0000

    SynEdit: win, IME Handler: Fixed (added) overwrite selection. Issue 0027712

    git-svn-id: http://svn.freepascal.org/svn/lazarus/trunk@48459 4005530d-fff6-0310-9dd1-cebe43e6787f

在这种情况下,输出会是这样的

date, git-commit, svn-commit, author, note
Mon Mar 23 00:45:30 2015 +0000, c49a28ae1, 48459, martin@xxxxx, SynEdit, etc

等等。 我尝试过使用一些命令,例如

# get the commit id of the nth revision
git log -n 1 | head -n 1 | cut -d " " -f 2

# get svn id of HEAD revision
git log -n 1 | head -n 7 | tail -n 1 | cut -d "@" -f 2 | cut -d " " -f 1

它变得相当笨拙和毛茸茸,我正在寻找更好的工具。

【问题讨论】:

    标签: git parsing svn text-extraction utilities


    【解决方案1】:

    我认为您正在寻找类似的东西:

    git log --format=format:"%ad,%h,,%ae,%s" <other selection parameters>
    

    除了不包括 svn id 之外(我不确定日期和电子邮件格式是否是您想要的)。大概 svn id 可以从完整的提交说明中提取,所以你应该能够使用像

    这样的格式
    --format=format:"%ad,%h,,%ae,%s%n%N"
    

    并通过gawk 脚本传递它,例如:

    awk 'NR==1{split($0,out,/,/);next;}
         match($0,/@[0-9]+/){out[3]=substr($0,RSTART+1,RLENGTH-1)}
         END{printf "%s,%s,%s,%s,%s\n",out[1],out[2],out[3],out[4],out[5]}'
    

    这些都没有经过测试。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 2021-06-18
      • 2012-12-01
      • 1970-01-01
      • 2012-02-23
      • 2018-02-23
      • 2020-11-09
      相关资源
      最近更新 更多