DEV Community

Lucian Ghinda
Lucian Ghinda

Posted on • Originally published at notes.ghinda.com

Bash one line to display git commit message without indentation

I like to write explanatory git commit messages and if the PR/MR has one single commit, I use the commit message as the body of the Pull Request/Merge Request.

Using the simple git log command displays the commit message but has some padding/indentation:

Screenshot of git log command

There is a way to fix this by specifying the format:



git log -1 --pretty='format:%s%n%n%b'


Enter fullscreen mode Exit fullscreen mode

Image with the output when executing a git command with format

Where:

  • %s is the subject of the commit message (the first line)
  • %n is adding a new line (so I am adding two)
  • %b is the body of the commit messageο»Ώ

You can make these bash aliases:



alias .lastmsg="git log -1 --pretty='format:%s%n%n%b'"


Enter fullscreen mode Exit fullscreen mode

And in case of MacOS you can directly copy the last message to clipboard:



alias .cplastmsg="git log -1 --pretty='format:%s%n%n%b' | pbcopy"


Enter fullscreen mode Exit fullscreen mode

PS: If you have some vacation days left (or want to work remote from another country) there is still time to buy tickets for Friendly.rb conference. I wrote here about why to participate

Top comments (0)