git --pretty选项字符串格式的别名 [英] An alias for git's --pretty option string format

查看:1129
本文介绍了git --pretty选项字符串格式的别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以为带有许多参数的git log调用设置别名.

I know I can set an alias for git log invocation with lots of parameters.

例如,我可以使用它:

git config --global alias.lg "log --graph --pretty=format:'%h -%d %s (%cr) <%an>'"

git lg短得多地作为git 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.

是否可以仅为--pretty=format:字符串设置别名?这样我就可以输入

Is it possible to set an alias for a --pretty=format: string alone? So that I can type

git log --pretty=my_aliased_format

推荐答案

git log文档表示--pretty[=<format>]--format=<format>选项(--format具有必需的<format>名称,而--pretty具有可选的名称).这段文字被深埋在 PRETTY FORMATS 部分下:

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:

有几种内置格式,您可以定义其他格式 通过设置漂亮格式.< name>配置选项到另一个 格式名称或 format:字符串,如下所述(请参见 git -- config(1)). ...

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)). ...

因此:

$ 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

只需从该部分列出的指令中编写您自己的格式,为其命名,然后将该名称放入您的配置中(本地或全局),然后--format=<name>将对其进行访问.

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.

像在前面的示例中一样,将lg设置为别名是更典型和常规的做法,但这也很好.

It's more typical and conventional to set lg as an alias, as in your earlier example, but this works well too.

这篇关于git --pretty选项字符串格式的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆