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:
There is a way to fix this by specifying the format:Â
git log -1 --pretty='format:%s%n%n%b'
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'"
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"
Why the dot in the aliases?
I like to differentiate my own defined aliases from the any bash command. And it also makes sure there is no conflict or redefining existing aliases/Linux commands.Â