git操作记录贴

git操作记录贴

整理log信息

  1. 要求在版本更新时获取到本次的更新记录:包含commit ID、root cause & solution、changeID、file list:

    上述所有信息都会添加在commit信息中,即可以通过git log信息获取到详细信息,或者gerrit上查看每一笔change

    不过既然提出了需求,那就将上述信息在更新推送时保存到文件中吧:

    • git log --pretty=format:“commit %H” %n “%b” commitID1…commitID2 >> release_log.txt
    • git diff --name-only commitID1 commitID2 --stat >> release_log.txt

    对每一个仓库执行上述操作即可

  2. 相关用法:

    1. git log --help

    2. git diff --help

    3. pretty 格式重定义占位符:

      ‘%H’: commit hash

      ‘%h’: abbreviated commit hash

      ‘%T’: tree hash

      ‘%t’: abbreviated tree hash

      ‘%P’: parent hashes

      ‘%p’: abbreviated parent hashes

      ‘%an’: author name

      ‘%aN’: author name (respecting .mailmap, see git-shortlog or git-blame)

      ‘%ae’: author email

      ‘%aE’: author email (respecting .mailmap, see git-shortlog or git-blame)

      ‘%ad’: author date (format respects --date= option)

      ‘%aD’: author date, RFC2822 style

      ‘%ar’: author date, relative

      ‘%at’: author date, UNIX timestamp

      ‘%ai’: author date, ISO 8601-like format

      ‘%aI’: author date, strict ISO 8601 format

      ‘%cn’: committer name

      ‘%cN’: committer name (respecting .mailmap, see git-shortlog or git-blame)

      ‘%ce’: committer email

      ‘%cE’: committer email (respecting .mailmap, see git-shortlog or git-blame)

      ‘%cd’: committer date (format respects --date= option)

      ‘%cD’: committer date, RFC2822 style

      ‘%cr’: committer date, relative

      ‘%ct’: committer date, UNIX timestamp

      ‘%ci’: committer date, ISO 8601-like format

      ‘%cI’: committer date, strict ISO 8601 format

      ‘%d’: ref names, like the --decorate option of git-log

      ‘%D’: ref names without the " (", “)” wrapping.

      ‘%e’: encoding

      ‘%s’: subject

      ‘%f’: sanitized subject line, suitable for a filename

      ‘%b’: body

      ‘%B’: raw body (unwrapped subject and body)

      ‘%N’: commit notes

gerrit 命令操作

git在提交后需要进行review后才可以实际入库,则存在这样一种场景,版本更新时服务器A将一个月的所有change批量推送到服务器B,这些在ServerA都是测试通过的,通过ServerB推送给到other使用,则这个时候既需要看到每一笔change信息,又不想手动review(change基本在200左右,手动点击一轮需要半小时以上),则找到如下命令使用:

  • gerrit query

    ssh -p <port> <host> gerrit query
      [--format {TEXT | JSON}] # 输出格式
      [--current-patch-set] # 当前patch set 信息
      [--patch-sets | --all-approvals] #所有
      [--files]
      [--comments]
      [--commit-message] # commit信息
      [--dependencies]
      [--submit-records]
      [--all-reviewers] # reviewer的name 和 email
      [--start <n> | -S <n>]
      <query> # 支持如下选项
    

    status:open 等价于 status:pending, is:open, is:pending
    owner:self 等价于 is:owner
    reviewer:self 等价于 is:reviewer
    project:buto/bba 或 p:buto/ba
    projects:bb
    branch:develop 或 branch:refs/heads/develop
    change:2311176 或 change:I03369813660369e983b56dcabe44cb48839be4de0
    commit:4e8ea8d43ab22273e49493484e1e7316f88cd54e3
    ref:refs/changes/76/2311476/1
    message:my_commit_message
    is:visible
    label:Code-Review=2 或 label:Code-Review=+2或label:Code-Review+2
    label:Verified+1

    举例:

    ssh -p 29418  $user gerrit query --format=JSON  status:open branch:$branch --current-patch-set
    

    以当前user作为登录用户搜索status为open的change,以JSON格式输出

  • gerrit review

    ssh -p 29418 $user gerrit review --verified +1 --code-review +2 --submit $commitID
    

    在上述gerrit query中的到的commitID信息,通过gerrit review操作进行review & submit操作

整体可以通过上述两个命令完成脚本实现自动review功能


版权声明:本文为xiaoqiaoq0原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。