git log formatting

后端 未结 4 1466
不思量自难忘°
不思量自难忘° 2021-01-30 23:52

I need to have format like:

git log --decorate --graph --oneline --date-order

but I need it also:

  1. to contain date (short)
4条回答
  •  被撕碎了的回忆
    2021-01-31 00:10

    Well, "impossible" means that there is no easy way and I'll have to do it myself. I worried too much that I always make things the hard way, when there is actually easier way.

    Here is a bash+php script. I tried to make it with sed, but I failed.

    I named this script git-gd and put it in a bin directory that's in path /usr/local/bin/ and I use it with git: git gd or git gd

    #!/bin/bash
    
    GIT="/usr/local/bin/git"
    PHP="/bin/php"
    GIT_DATES="$GIT log --date=short --abbrev-commit --pretty=format:%C(yellow)%h_%C(green)[%ad]%Creset --branches --color=always $*"
    #if you have have alias g
    GIT_GRAPH="$GIT g --color=always"
    #or
    #GIT_GRAPH="$GIT log --decorate --graph --oneline --date-order --color=always"
    PHP_SCRIPT='
      $exps = explode("\n", $_SERVER["argv"][1]);
      $lines = file("php://stdin");
      $s = array();
      $r=$s;
      foreach($exps as $exp){
       $exp = trim($exp);
       list($commit,)=explode("_", $exp);
       $s[] = $commit;
       $r[] = str_replace("_", " ", $exp);
      }
      foreach($lines as $line){
        $line = str_replace($s, $r, $line);
        echo $line ;
      }
      '
    
    DATES=`$GIT_DATES`
    $GIT_GRAPH $* |$PHP -r "$PHP_SCRIPT" -- "$DATES"
    

    I'll wait a bit for simpler solution and I'll accept my own answer

提交回复
热议问题