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](https://scribbles.page/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBaCtQIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--92dee90a5f7980ce9fbf9b9c9620997c9ca9094a/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9MWm05eWJXRjBTU0lJY0c1bkJqb0dSVlE2RkhKbGMybDZaVjkwYjE5c2FXMXBkRnNIYVFJQUNHa0NBQVk2Q25OaGRtVnlld2M2Q25OMGNtbHdWRG9NY1hWaGJHbDBlV2xrIiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--768aeab7fb7843d85fe5b2b4ba237e06e6ef604f/1.png)
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
![Image with the output when executing a git command with format](https://scribbles.page/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBaUNQIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--950af188d758007c1b2220d213d5803c63a6e07f/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9MWm05eWJXRjBTU0lJY0c1bkJqb0dSVlE2RkhKbGMybDZaVjkwYjE5c2FXMXBkRnNIYVFJQUNHa0NBQVk2Q25OaGRtVnlld2M2Q25OMGNtbHdWRG9NY1hWaGJHbDBlV2xrIiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--768aeab7fb7843d85fe5b2b4ba237e06e6ef604f/2.png)
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.Â