Print git commits body lines joined in one line

前端 未结 2 1472
[愿得一人]
[愿得一人] 2020-12-19 05:50

How can I print git commits to print only body (commit message without title) but in one line? So commit body lines are joined, possibly separated with space, and printed as

相关标签:
2条回答
  • 2020-12-19 06:12
    git rev-list master |
        while read sha1; do
            git show -s --format='%B' $sha1 | tr -d '\n'; echo
        done
    

    Let me explain:

    git rev-list master
    

    List SHA1 IDs of commits in the branch.

        while read sha1; do
    

    Run a loop over every SHA1.

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

    Show the body of the commit.

            tr -d '\n'
    

    Remove all line endings.

            echo
    

    Add one newline at the end.

    0 讨论(0)
  • 2020-12-19 06:15

    "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:

    0 讨论(0)
提交回复
热议问题