Home > database >  git command to retrieve latest git commit message
git command to retrieve latest git commit message

Time:09-27

I want to retrieve the latest git commit message from my branch , only 'commit' message nothing else ,

I found commands like git log -1 --pretty=format:%B which returns below , however i need only commit message "Add columns to list view" , i also tried '%s' and '%b' but no luck.

      Merge branch 'mos-changes' into 'uat'

      Add columns to list view

      See merge request mos/mos-changes!103

CodePudding user response:

git show --format=%b -s 

%b is (message) body (%s is subject if you need that), and -s means don't show the diff. "Merge branch" may be part of the commit message, in which case you can use grep -v or sed to filter that out.

CodePudding user response:

There are several commands from git to get only commit messages. git-rev-list is the plumbing command that let's you print the message of a commit. Use it like this.

1.git rev-list --format=%B --max-count=1 <commit> | tail  2
2.git show-branch --no-name <hash>
3. git show -s --format=%s <hash>
4. $ git log --format=%B -n 1 <commit>
  •  Tags:  
  • git
  • Related