【问题标题】:How to get the author of the last commit in Git?如何获取 Git 中最后一次提交的作者?
【发布时间】:2017-01-09 13:02:25
【问题描述】:

如何获取 Git 仓库中最新提交的作者?

#!/bin/bash

git_log=`git ls-remote git url  master`
git_commitId = git_log | cut -d " " -f1
echo $git_commitId

cd /workspace
git_log_verify = `git rev-parse HEAD`
echo $git_log_verify

if $git_commitId =$git_log_verify then
    cd /workspace
    git_authorName=`git log --pretty=format:"%an"`;
    echo $git_authorName
fi

【问题讨论】:

    标签: git author


    【解决方案1】:

    这就是你要找的东西:

    git log -1 --pretty=format:'%an'
    

    【讨论】:

    • 如果您需要此脚本或变量,只需添加xargs,例如。 git log -1 --pretty=format:'%an' | xargs
    • 你从哪里得到所有的转义码?
    【解决方案2】:

    或检索作者的电子邮件,而不是姓名:

    git log -1 --pretty=format:'%ae'
    

    【讨论】:

      【解决方案3】:

      获取作者姓名

      git log -1 --pretty=format:'%an'
      

      要获得作者电子邮件

      git log -1 --pretty=format:'%ae'
      

      【讨论】:

        【解决方案4】:

        如何在 Groovy 中赋值给变量:

        def builtBy = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%an'").trim()
        

        【讨论】:

          猜你喜欢
          • 2017-06-19
          • 2012-08-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-05
          • 2011-02-20
          • 2011-01-21
          • 1970-01-01
          相关资源
          最近更新 更多