Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A git log history graph with one line per commit, in color, with dates

Tags:

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 
like image 395
NickSoft Avatar asked Sep 15 '11 11:09

NickSoft


People also ask

What do the colors mean on git log graph?

The colors are merely meant to help you view the lines as distinct from other lines. To answer question #1, they are assigned not pseudo-randomly, but rather sequentially, each time git log --graph picks a new "column number".

What does the command git log Oneline graph?

git log by default shows the entire ancestry in order by birthdate (where timestamp weirdities don't make that contradict ancestry). Try it with git log --oneline --graph --decorate --first-parent . ^ or ^1 means the first parent.


2 Answers

You can try:

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

It has different color, but you can change them easily.

for instance:

git log --graph --pretty=format:'%Cred%h -%d %s (%cr) <%an>%Creset' --abbrev-commit --date=short --branches 
like image 92
VonC Avatar answered Nov 17 '22 18:11

VonC


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

like image 44
NickSoft Avatar answered Nov 17 '22 16:11

NickSoft