DEV Community

Lucian Ghinda
Lucian Ghinda

Posted on • Originally published at notes.ghinda.com

2 1

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

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup 🚀

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay