git日志格式 [英] git log formatting

查看:151
本文介绍了git日志格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

但我也需要:


  1. 包含日期(简称)
  2. 具有相同的颜色



<我尝试过:
$ b $ pre $ git log --decorate --graph --oneline --date-order \
- date = short --pretty = format:%h%ad%s

但它很难阅读(没有颜色),不包括分支/标签




最简单的解决方案是(谢谢):

  git日志--graph --pretty =格式:%C(黄色)%h%Creset \ 
- %C(黄色)%d%Creset%s%Cgreen(%cr)%C(粗体蓝色) <%an>%Creset'\
--abbrev-commit --date = short


那么,不可能意味着没有简单的方法,我会必须自己做。我太担心,当事情真的变得简单的时候,我总是让事情变得艰难。



这是一个bash + php脚本。

我将这个脚本命名为git-gd,并把它放在路径为的bin目录下, / usr / local / bin / ,我用git: git gd git gd< options> / code>

 #!/ bin / bash 

GIT =/ usr / local / bin / git
PHP =/ bin / php
GIT_DATES =$ GIT log --date = short --abbrev-commit --pretty = format:%C(yellow)%如果你有别名g
GIT_GRAPH =$ GIT g --color = always
#或
#GIT_GRAPH =$ GIT log --decorate --graph --oneline --date-order --color = always
PHP_SCRIPT ='
$ exps = explode(\\\
,$ _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;


$ b $ DATES =`$ GIT_DATES`
$ GIT_GRAPH $ * | $ PHP -r$ PHP_SCRIPT - $ DATES

我会稍微等待一下简单的解决方法,我会接受我自己的答案。

I need to have format like:

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

but I need it also:

  1. to contain date (short)
  2. to have the same colors

I tried:

git log --decorate --graph --oneline --date-order \
--date=short --pretty=format:"%h %ad %s"

but it's harder to read (no colors) and does not include branches/tags


The closest simple solution is(thanks VonC):

git log --graph --pretty=format:'%C(yellow)%h%Creset \
-%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \
--abbrev-commit --date=short

解决方案

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 <options>

#!/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

这篇关于git日志格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆