I am trying to recreate the Git format setting of oneline
as a format string (in order to extend it further).
So for this command
git log --format=oneline
What is the format string equivalent of oneline
?
The closest I can get is
git log --format="%h %d %s"
However, this does not produce any colors. I know I can hard code some of them, like the commit hash. But the %d has dynamic colors, depending on what it shows.
<full-commit-message> reference. <abbrev-hash> (<title-line>, <short-author-date>) This format is used to refer to another commit in a commit message and is the same as --pretty='format:%C(auto)%h (%s, %ad)' . By default, the date is formatted with --date=short unless another --date option is explicitly specified.
A simple fix is to pass the --pretty=oneline parameter, which makes it all fit on a single line. It's taking up less space, but missing crucial information like the date of the commit. There are longer versions of that same --pretty parameter. In fact, it allows you to specify all the fields you want in the output.
This is commonly used in conjunction with the --oneline and --decorate commands to make it easier to see which commit belongs to which branch: git log --graph --oneline --decorate.
The git log command shows a list of all the commits made to a repository. You can see the hash of each Git commit, the message associated with each commit, and more metadata. This command is useful for displaying the history of a repository.
Turn on auto color
git log --format="%C(auto) %h %d %s"
and the output will look like this
From the git log documentation
%C(…): color specification, as described in color.branch.* config option; adding auto, at the beginning will emit color only when colors are enabled for log output (by color.diff, color.ui, or --color, and respecting the auto settings of the former if we are going to a terminal). auto alone (i.e. %C(auto)) will turn on auto coloring on the next placeholders until the color is switched again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With