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

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay