How to get the author of the last commit in Git?

34k views Asked by At

How to get the author of the latest commit in a Git repository?

#!/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
4

There are 4 answers

3
John Bupit On

This is what you're looking for:

git log -1 --pretty=format:'%an'
0
smmehrab On

To get author name:

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

To get author email:

git log -1 --pretty=format:'%ae'
0
Donald Steffy On

Or to retrieve the author's email, instead of name:

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

how to assign to variable in Groovy:

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