The shortest possible output from git log containing author and date

前端 未结 13 1661
我在风中等你
我在风中等你 2020-12-02 03:12

How can I show a git log output with (at least) this information:

* author
* commit date
* change

I want it compressed to one line per log

相关标签:
13条回答
  • 2020-12-02 03:44

    All aforementioned suggestions use %s placeholder for subject. I'll recommend to use %B because %s formatting preserves new lines and multiple lines commit message appears squashed.

    git log --pretty=format:"%h%x09%an%x09%ai%x09%B"
    
    0 讨论(0)
  • 2020-12-02 03:45

    Feel free to use this one:

    git log --pretty="%C(Yellow)%h  %C(reset)%ad (%C(Green)%cr%C(reset))%x09 %C(Cyan)%an: %C(reset)%s" -7
    

    Note the -7 at the end, to show only the last 7 entries.

    Look:

    0 讨论(0)
  • 2020-12-02 03:47
    git log --pretty=format:'%h %ad  %s%x09%ae' --date=short
    

    Result:

    e17bae5 2011-09-30  Integrate from development -> main      nixon@whitehouse.gov
    eaead2c 2011-09-30  More stuff that is not worth mentioning bgates@apple.com
    eb6a336 2011-09-22  Merge branch 'freebase' into development        jobs@nirvana.org
    

    Constant-width stuff is first. The least important part -- the email domain -- is last and easy to filter.

    0 讨论(0)
  • 2020-12-02 03:49

    tig is a possible alternative to using the git log command, available on the major open source *nix distributions.

    On debian or ubuntu try installing and running as follows:

    $ sudo apt-get install tig
    

    For mac users, brew to the rescue :

    $ brew install tig
    

    (tig gets installed)

    $ tig
    

    (log is displayed in pager as follows, with current commit's hash displayed at the bottom)

    2010-03-17 01:07 ndesigner      changes to sponsors list
    2010-03-17 00:19 rcoder         Raise 404 when an invalid year is specified.
    2010-03-17 00:06 rcoder         Sponsors page now shows sponsors' level.
    -------------------------- skip some lines ---------------------------------
    [main] 531f35e925f53adeb2146dcfc9c6a6ef24e93619 - commit 1 of 32 (100%)
    

    Since markdown doesn't support text coloring, imagine: column 1: blue; column 2: green; column 3: default text color. Last line, highlighted. Hit Q or q to exit.


    tig justifies the columns without ragged edges, which an ascii tab (%x09) doesn't guarantee.

    For a short date format hit capital D (note: lowercase d opens a diff view.) Configure it permanently by adding show-date = short to ~/.tigrc; or in a [tig] section in .git/configure or ~/.gitconfig.

    To see an entire change:

    • hit Enter. A sub pane will open in the lower half of the window.
    • use k, j keys to scroll the change in the sub pane.
    • at the same time, use the up, down keys to move from commit to commit.

    Since tig is separate from git and apparently *nix specific, it probably requires cygwin to install on windows. But for fedora I believe the install commands are $ su, (enter root password), # yum install tig. For freebsd try % su, (enter root password), # pkg_add -r tig.


    By the way, tig is good for a lot more than a quick view of the log: Screenshots & Manual

    0 讨论(0)
  • 2020-12-02 03:52

    git log --pretty=format:"%h%x09%an%x09%ad%x09%s"

    did the job. This outputs:

      fbc3503 mads    Thu Dec 4 07:43:27 2008 +0000   show mobile if phone is null...   
      ec36490 jesper  Wed Nov 26 05:41:37 2008 +0000  Cleanup after [942]: Using timezon
      ae62afd tobias  Tue Nov 25 21:42:55 2008 +0000  Fixed #67 by adding time zone supp
      164be7e mads    Tue Nov 25 19:56:43 2008 +0000  fixed tests, and a 'unending appoi
      93f1526 jesper  Tue Nov 25 09:45:56 2008 +0000  adding time.ZONE.now as time zone 
      2f0f8c1 tobias  Tue Nov 25 03:07:02 2008 +0000  Timezone configured in environment
      a33c1dc jesper  Tue Nov 25 01:26:18 2008 +0000  updated to most recent will_pagina
    

    Inspired by stackoverflow question: "git log output like svn ls -v", i found out that I could add the exact params I needed.

    To shorten the date (not showing the time) use --date=short

    In case you were curious what the different options were:
    %h = abbreviated commit hash
    %x09 = tab (character for code 9)
    %an = author name
    %ad = author date (format respects --date= option)
    %s = subject
    From kernel.org/pub/software/scm/git/docs/git-log.html (PRETTY FORMATS section) by comment of Vivek.

    0 讨论(0)
  • 2020-12-02 03:53
    git log --pretty=format:'%h %ad %s (%an)' --date=short  
    

    or

    git log --pretty=format:'%h %ad %s | %an' --date=short  
    

    ...riffing on cdunn2001's answer above: I'd lose the author's e=mail and include just the author's name, as per Jesper and knittl, but in keeping with cdunn2001's idea of maintaining output in columns of constant width for ease of reading (great idea!). In lieu of a separate left justified column for author name, however, I wrap that flag at the end of the command with a parentheses or offset it with a pipe. (Could really be any character that serves as a visual aid in reading the output...albeit might make sense to avoid back or forward slashes in order to reduce confusing the output with a directory or something.)

    Sample output:

    6fdd155 2015-08-10 Fixes casting error in doSave | John Doe
    c4f4032 2015-08-10 Fix for IE save. Add help button. | Jane
    29a24a6 2015-08-10 Fixes bug in Course | Mac
    
    0 讨论(0)
提交回复
热议问题