打印 git 提交 body 行合并为一行

Print git commits body lines joined in one line

如何打印 git 提交仅打印 body(没有标题的提交消息)但在一行中?因此,提交 body 行被合并,可能用 space 分隔,并打印为一次提交的一行。

例如,有两个提交 A 和 B,命令:

$ git log --format=%b

打印:

Commit A, line A.1
Commit A, line A.2
Commit B, line B.1
Commit B, line B.2

但我想得到:

Commit A, line A.1 Commit A, line A.2
Commit B, line B.1 Commit B, line B.2
git rev-list master |
    while read sha1; do
        git show -s --format='%B' $sha1 | tr -d '\n'; echo
    done

让我解释一下:

git rev-list master

列出分支中提交的 SHA1 ID。

    while read sha1; do

运行 对每个 SHA1 进行循环。

        git show -s --format='%B' $sha1

显示提交正文。

        tr -d '\n'

删除所有行尾。

        echo

末尾加一换行。

"3. By default, git log prints the commit, author's name and email ID, timestamp, and the commit message. However, the information isn't very graphical, especially if you want to see branches and merges. To display this information and limit some of the other data, you can use the following options with git log: $ git log --decorate --graph --oneline --all" ("Viewing the DAG, How to do it..." section of "Git Version Control Cookbook: Leverage version control to transform your development workflow and boost productivity, 2nd Edition"; by Aske Olsson, Rasmus Voss, Emanuele Zattin, Kenneth Geisshirt; publisher: Packt Publishing).

在向我的老板发送电子邮件时,有时我需要参考最近的提交或特定提交的列表。例如,我曾经完全依赖 git log -3 来显示最后三个提交。不幸的是,这种方法很冗长(每个提交都包含多行)并且没有显示这些提交所属的分支。我开始使用 git log --decorate --graph --oneline --all,它允许我显示每个提交所属的分支。我还喜欢这种新方法的一点是,每个提交都使用一行进行总结:

C:\Users\jaimemontoya\[path]\app>git log --decorate --graph --oneline --all
* 99d200c (HEAD -> improvedatesformat, origin/improvedatesformat) Subtract 4 hours to the date and time stored in the database because the database uses GMT but El Salvador and Guatemala use GMT-4.
* 244a7a9 Use date() and strtotime() to format date/time in an easy to read format without the verbose and inefficient approach of multiple switch case statements.
* 4d38145 Change date format to 5 June 2020 instead of 06/05/2020 to avoid ambiguity.
* 501d4e4 (markP/subscriptions, marksubscriptions) Change CAPTCHA to reCAPTCHA for contact us form.
* fc860b2 Add ability to send country-wide bulk emails using a template other than Default Template.
* 7f9d2e7 (origin/addsubscriptiontemplates, subscriptionbanneradministration, addsubscriptiontemplates) Remove code that supported template pictures uploaded to media directory, since that implementation was abandoned.
* f6ea277 Add models/subscription_template.php, the version that no longer contains the code that associates pictures to subscription templates.
* 4373e7a Merge branch 'marksubscriptions' into addsubscriptiontemplates

查看它的颜色格式: