8

如何打印 git commits 以仅打印正文(没有标题的提交消息)但在一行中?因此,提交正文行被连接起来,可能用空格分隔,并打印为一次提交的一行。

例如,有两个提交 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
4

2 回答 2

7
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

在末尾添加一个换行符。

于 2018-03-28T16:04:23.793 回答
0

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

When sending emails to my boss, sometimes I needed to refer to the most recent commits or to a list of specific commits. I used to rely solely on git log -3 for example to display the last three commits. Unfortunately, that approach was verbose (each commit included multiple lines) and did not show the branch(es) that those commits belonged to. I started to use git log --decorate --graph --oneline --all, which allows me to show the branch(es) that each commit belongs to. Something I also like about this new approach is that each commit is summarized using a single line:

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

See it formatted with colors:

enter image description here

于 2020-07-22T16:48:40.637 回答