Reputation: 1972
I know I can set an alias for git log
invocation with lots of parameters.
For example, I can use this:
git config --global alias.lg "log --graph --pretty=format:'%h -%d %s (%cr) <%an>'"
to alias git log --graph --pretty=format:'%h -%d %s (%cr) <%an>'
with much shorter git lg
.
Is it possible to set an alias for a --pretty=format:
string alone? So that I can type
git log --pretty=my_aliased_format
Upvotes: 2
Views: 286
Reputation: 488599
The git log
documentation has this to say about the --pretty[=<format>]
and --format=<format>
options (the --format
one has a required <format>
name while --pretty
has an optional one). This text is buried fairly far in, under the section PRETTY FORMATS:
There are several built-in formats, and you can define additional formats by setting a pretty.<name> config option to either another format name, or a format: string, as described below (see git- config(1)). ...
Hence:
$ git config pretty.foo 'bar %H baz' # you might want --global here
$ git log --format=foo | head -3
bar b5101f929789889c2e536d915698f58d5c5c6b7a baz
bar a562a119833b7202d5c9b9069d1abb40c1f9b59a baz
bar 7fa92ba40abbe4236226e7d91e664bbeab8c43f2 baz
Simply write your own format from the directives listed in that section, give it a name, and put that name into your configuration (local or global) and then --format=<name>
will access it.
It's more typical and conventional to set lg
as an alias, as in your earlier example, but this works well too.
Upvotes: 3