The shortest possible output from git log containing author and date

前端 未结 13 1660
我在风中等你
我在风中等你 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 04:04

    To show the commits I have staged that are ready to push I do

    git log remotes/trunk~4..HEAD --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s" --date=short | awk -F'\t' '{gsub(/[, ]/,"",$2);gsub(/HEAD/, "\033[1;36mH\033[00m",$2);gsub(/master/, "\033[1;32mm\033[00m",$2);gsub(/trunk/, "\033[1;31mt\033[00m",$2);print $1 "\t" gensub(/([\(\)])/, "\033[0;33m\\1\033[00m","g",$2) $3}' | less -eiFRXS
    

    The output looks something like:

    ef87da7 2013-01-17 haslers      (Hm)Fix NPE in Frobble
    8f6d80f 2013-01-17 haslers      Refactor Frobble
    815813b 2013-01-17 haslers      (t)Add Wibble to Frobble
    3616373 2013-01-17 haslers      Add Foo to Frobble
    3b5ccf0 2013-01-17 haslers      Add Bar to Frobble
    a1db9ef 2013-01-17 haslers      Add Frobble Widget
    

    Where the first column appears in yellow, and the 'H' 'm' and 't' in parentesis show the HEAD, master and trunk and appear in their usual "--decorate" colors

    Here it is with line breaks so you can see what it's doing:

    git log remotes/trunk~4..HEAD --date=short
        --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s"
        | awk -F'\t' '{
             gsub(/[, ]/,"",$2);
             gsub(/HEAD/, "\033[1;36mH\033[00m",$2);
             gsub(/master/, "\033[1;32mm\033[00m",$2);
             gsub(/trunk/, "\033[1;31mt\033[00m",$2);
             print $1 "\t" gensub(/([\(\)])/, "\033[0;33m\\1\033[00m","g",$2) $3}'
    

    I have aliased to "staged" with:

    git config alias.staged '!git log remotes/trunk~4..HEAD --date=short --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s" | awk -F"\t" "{gsub(/[, ]/,\"\",\$2);gsub(/HEAD/, \"\033[1;36mH\033[00m\",\$2);gsub(/master/, \"\033[1;32mm\033[00m\",\$2);gsub(/trunk/, \"\033[1;31mt\033[00m\",\$2);print \$1 \"\t\" gensub(/([\(\)])/, \"\033[0;33m\\\\\1\033[00m\",\"g\",\$2) \$3}"'
    

    (Is there an easier way to escape that? it was a bit tricky to work out what needed escaping)

提交回复
热议问题