Git color graph

26/09/2011

Suite à deux excellents billets proposés par Gérald - Introduction à Git Partie 1 - et Partie 2 je vais vous présenter quelques petits “trucs” que j’utilise sur Git. Aujourd’hui parlons l’affichage de votre dépôt, dans une console, mais en mode “pretty”

Je sais qu’il existe un outil bien sympathique nommé “tig” (git à l’envers) qui est une interface assez bien fichue pour avoir une vue assez “lisible” de votre dépôt. Mais sans avoir à installer un outils en plus, git permet déjà de voir un “graph” de vos commits, merges et branches, et ce de manière propre.

Je vous montre les étapes de tests que j’ai effectué, mais souvenez vous qu’à la fin de l’article il y a la manière “rapide” qui est ni plus ni moins que l’a création d’un alias de commande à git. Pour le moment, laissez moi vous montrer comment j’ai procédé.

En fait, tout va passer par la commande “git log” dont des options vont être ajoutées. Si vous tapez simplement “git log” dans votre console, vous aurez un log, certes lisible, mais pas très sexy. Passons par la première options que j’aime bien:

git log --graph
*   commit 2a9910f060f7c75f93499307882e29977a3e8c57
|\  Merge: b760954 d50d7d9
| | Author: Patrice FERLET <metal3d@gmail.com>
| | Date:   Mon Sep 26 13:14:58 2011 +0200
| | 
| |     Merge branches 'developpement' and 'master'
| |   
| * commit d50d7d980664a061dbde83ee3ef3d8931fde5c97
| | Author: Patrice FERLET <metal3d@gmail.com>
| | Date:   Mon Sep 26 13:09:14 2011 +0200
| | 
| |     Append those files to be integrated into pypi... and make some dist packages
| |   
| * commit 8d775cb8fd1413f761404d423f9792a800a2e5ad
| | Author: Patrice FERLET <metal3d@gmail.com>
| | Date:   Mon Sep 26 13:08:42 2011 +0200
| | 
| |     This is an alpha release for now, not a beta
| |     Added Classifier section for pypi
| |   
* | commit b760954c324262a2e84b5c85d83a2fd8aa41d50f
|/  Author: Patrice FERLET <metal3d@gmail.com>
|   Date:   Mon Sep 26 12:46:15 2011 +0200
|   
|       Merge branches 'developpement' and 'master'
|  
* commit 5120b24072c31f5fe147a4b8ddc955594c613606
| Author: Patrice FERLET <metal3d@gmail.com>
| Date:   Mon Sep 26 12:45:48 2011 +0200
...

C’est déjà pas mal… nous avons ici une représentation des branches ainsi que le log de commit, l’auteur, etc… Bon admettez que c’est un peu “verbeux” et que certaines informations ne sont pas forcément “utiles”. Ajoutons une seconde option “--pretty=oneline”

 git log --graph --pretty=oneline
 *   2a9910f060f7c75f93499307882e29977a3e8c57 Merge branches 'developpement' and 'master'
 |\  
 | * d50d7d980664a061dbde83ee3ef3d8931fde5c97 Append those files to be integrated into pypi... and make some dist
 | * 8d775cb8fd1413f761404d423f9792a800a2e5ad This is an alpha release for now, not a beta Added Classifier secti
 * | b760954c324262a2e84b5c85d83a2fd8aa41d50f Merge branches 'developpement' and 'master'
 |/  
 * 5120b24072c31f5fe147a4b8ddc955594c613606 What next section correction
 * e5fbc7c9401e5719e5954f280e3074138fe9daae Merge branches 'master' and 'developpement' into developpement
 * 413e236a5ee30895df7bd254f58dc00bee06c816 Changes english errors (excuse my english, I'm french...)
 *   a4d8baa02d46a8e91b2458f58f9540c906fd5db4 Merge branches 'developpement' and 'master'
 |\  
 | * 811c711b894bf929e720e4fa77dc9c887f3542b1 English errors correction (thanks vim spell :))
 | * dae1d7a4c2cc32b0703436383fe2a3c187c04bcc Excpetion declaration to raise proper errors
 | * 9f1569f85248e502473949cabd930b71048ac72d Cython allow to declare enum without given values. Values are taken
 * |   fa56bdda9029f9f5e35e8fc3b25ecfe9dd7b1f2a Merge branches 'developpement' and 'master'
 |\ \  
 | |/  
 | * e8e732b94a307f78baa5384ad196b18792b98c47 Change example in code doc comment
 | * 4e5db330a9a5f30ad1986e64f12ba34b786b6abc Removed "Queue" in thread example
 | * e0163a32cd110e94e67cdc38f315b0652583e151 Better documentation
 | * adf50978af73c90b31066c6cb2fcdbb0ea7125bb Back to a Quvi classes, that allows to use several Quvi instances
 | * f9f9944b8e5348a6e026c9af14dcf33f4a4ebaaa Append additionnal information on setup
 * |   2c9e704e021434e1b39d16c79225a687c5408fbc Merge branches 'developpement' and 'master'
 |\ \  

 ...

Ah, là on avance, bon on va réduire le checksum de commit avec “--abbrev-commit”:

 git log --graph --pretty=oneline --abbrev-commit 
 *   2a9910f Merge branches 'developpement' and 'master'
 |\  
 | * d50d7d9 Append those files to be integrated into pypi... and make some dist packages
 | * 8d775cb This is an alpha release for now, not a beta Added Classifier section for pypi
 * | b760954 Merge branches 'developpement' and 'master'
 |/  
 * 5120b24 What next section correction
 * e5fbc7c Merge branches 'master' and 'developpement' into developpement
 * 413e236 Changes english errors (excuse my english, I'm french...)
 *   a4d8baa Merge branches 'developpement' and 'master'
 |\  
 | * 811c711 English errors correction (thanks vim spell :))
 | * dae1d7a Excpetion declaration to raise proper errors
 | * 9f1569f Cython allow to declare enum without given values. Values are taken from header. see: quvi.h
 * |   fa56bdd Merge branches 'developpement' and 'master'
 |\ \  
 | |/  
 | * e8e732b Change example in code doc comment
 | * 4e5db33 Removed "Queue" in thread example
 | * e0163a3 Better documentation
 | * adf5097 Back to a Quvi classes, that allows to use several Quvi instances
 | * f9f9944 Append additionnal information on setup
 * |   2c9e704 Merge branches 'developpement' and 'master'
 |\ \  
 | |/  
 | * f5e91bb change documentation
 | * 928d007 Mini changes on comments and doc
 * |   cac294e Merge branches 'developpement' and 'master'
 |\ \  

Sympa ! Reste deux options, dont une qui peut s’avérer utile mais malheureusement pas très visible dans mon exemple, les option “--branches” et “--color”. La première, comme je vous le disais, n’est pas visible ici, par contre, la couleur oui !:

Reste alors un petit souci… cette commande est un peu longue à taper. Qu’à cela ne tienne, ajoutons notre “alias” dans notre fichier ~/.gitconfig:

[alias]
    graph = log --color --graph --decorate --abbrev-commit --pretty=oneline --branches

Et de ce fait, les graphs sont directement utilisables de cette manière:

git graph
#ou
git graph --all

Notez que j’ai ajouté “--decorate” qui permet de voir les nom de branches, merges etc… en couleur.

Un dernier point, “git log” utilise le mode de lecture de log avec less, ce qui permet:

-la recherche avec la commande “/” -enregistrer le log avec la commande “s” --> la couleur est aussi enregistrée dans le fichier.

D’ailleurs, en parlant de cela, un module perl vous permet de resortir du code ansi en HTML, voici comment installer le module:

cpan i /HTML-FromANSI/

Reste alors à faire cette manipulation:

ansi2html <(git graph --all) > log.html

Surtout n’oubliez pas: **aucun espace entre le “<” et “(git graph --all”**, cela à pour effet de créer un fichier “log.html”.

Si vous ne voulez que le “corps” du fichier, pour l’injecter dans une page, utilisez la méthode ci-dessous:

xmllint --html --xpath "//body/*" <( ansi2html <(git graph --all) ) > log-body.html

Cela vous donnera ce résultat:

<font face="fixedsys, lucida console, terminal, vga, monospace" style="line-height: 1; letter-spacing: 0; font-size: 12pt"><span style="color: gray; background: black; ">*   </span><span style="color: #8b8b00; background: black; ">2a9910f (</span><span style="color: cyan; background: black; ">HEAD</span><span style="color: #8b8b00; background: black; ">, </span><span style="color: yellow; background: black; ">tag: 0.0.1-alpha1</span><span style="color: #8b8b00; background: black; ">, </span><span style="color: red; background: black; ">origin/master</span><span style="color: #8b8b00; background: black; ">, </span><span style="color: green; background: black; ">master</span><span style="color: #8b8b00; background: black; ">)</span><span style="color: gray; background: black; "> Merge branches 'developpement' and 'master'                      </span><span style="color: black; background: black; "><br></span><span style="color: darkred; background: black; ">|</span><span style="color: darkgreen; background: black; ">\</span><span style="color: gray; background: black; ">                                                                                                                            </span><span style="color: black; background: black; "><br></span><span style="color: darkred; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">d50d7d9 (</span><span style="color: red; background: black; ">origin/developpement</span><span style="color: #8b8b00; background: black; ">, </span><span style="color: green; background: black; ">developpement</span><span style="color: #8b8b00; background: black; ">)</span><span style="color: gray; background: black; "> Append those files to be integrated into pypi... and make some dist packages</span><span style="color: black; background: black; "><br></span><span style="color: darkred; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">8d775cb</span><span style="color: gray; background: black; "> This is an alpha release for now, not a beta Added Classifier section for pypi                                    </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: darkgreen; background: black; ">|</span><span style="color: gray; background: black; "> </span><span style="color: #8b8b00; background: black; ">b760954</span><span style="color: gray; background: black; "> Merge branches 'developpement' and 'master'                                                                       </span><span style="color: black; background: black; "><br></span><span style="color: darkgreen; background: black; ">|/</span><span style="color: gray; background: black; ">                                                                                                                            </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: #8b8b00; background: black; ">5120b24</span><span style="color: gray; background: black; "> What next section correction                                                                                        </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: #8b8b00; background: black; ">e5fbc7c</span><span style="color: gray; background: black; "> Merge branches 'master' and 'developpement' into developpement                                                      </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: #8b8b00; background: black; ">413e236</span><span style="color: gray; background: black; "> Changes english errors (excuse my english, I'm french...)                                                           </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">*   </span><span style="color: #8b8b00; background: black; ">a4d8baa</span><span style="color: gray; background: black; "> Merge branches 'developpement' and 'master'                                                                       </span><span style="color: black; background: black; "><br></span><span style="color: #8b8b00; background: black; ">|</span><span style="color: darkblue; background: black; ">\</span><span style="color: gray; background: black; ">                                                                                                                            </span><span style="color: black; background: black; "><br></span><span style="color: #8b8b00; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">811c711</span><span style="color: gray; background: black; "> English errors correction (thanks vim spell :))                                                                   </span><span style="color: black; background: black; "><br></span><span style="color: #8b8b00; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">dae1d7a</span><span style="color: gray; background: black; "> Excpetion declaration to raise proper errors                                                                      </span><span style="color: black; background: black; "><br></span><span style="color: #8b8b00; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">9f1569f</span><span style="color: gray; background: black; "> Cython allow to declare enum without given values. Values are taken from header. see: quvi.h                      </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: darkblue; background: black; ">|</span><span style="color: gray; background: black; ">   </span><span style="color: #8b8b00; background: black; ">fa56bdd</span><span style="color: gray; background: black; "> Merge branches 'developpement' and 'master'                                                                     </span><span style="color: black; background: black; "><br></span><span style="color: darkmagenta; background: black; ">|</span><span style="color: darkblue; background: black; ">\</span><span style="color: gray; background: black; "> </span><span style="color: darkblue; background: black; ">\</span><span style="color: gray; background: black; ">                                                                                                                          </span><span style="color: black; background: black; "><br></span><span style="color: darkmagenta; background: black; ">|</span><span style="color: gray; background: black; "> </span><span style="color: darkblue; background: black; ">|/</span><span style="color: gray; background: black; ">                                                                                                                          </span><span style="color: black; background: black; "><br></span><span style="color: darkmagenta; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">e8e732b</span><span style="color: gray; background: black; "> Change example in code doc comment                                                                                </span><span style="color: black; background: black; "><br></span><span style="color: darkmagenta; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">4e5db33</span><span style="color: gray; background: black; "> Removed "Queue" in thread example                                                                                 </span><span style="color: black; background: black; "><br></span><span style="color: darkmagenta; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">e0163a3</span><span style="color: gray; background: black; "> Better documentation                                                                                              </span><span style="color: black; background: black; "><br></span><span style="color: darkmagenta; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">adf5097</span><span style="color: gray; background: black; "> Back to a Quvi classes, that allows to use several Quvi instances                                                 </span><span style="color: black; background: black; "><br></span><span style="color: darkmagenta; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">f9f9944</span><span style="color: gray; background: black; "> Append additionnal information on setup                                                                           </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: darkcyan; background: black; ">|</span><span style="color: gray; background: black; ">   </span><span style="color: #8b8b00; background: black; ">2c9e704</span><span style="color: gray; background: black; "> Merge branches 'developpement' and 'master'                                                                     </span><span style="color: black; background: black; "><br></span><span style="color: red; background: black; ">|</span><span style="color: darkcyan; background: black; ">\</span><span style="color: gray; background: black; "> </span><span style="color: darkcyan; background: black; ">\</span><span style="color: gray; background: black; ">                                                                                                                          </span><span style="color: black; background: black; "><br></span><span style="color: red; background: black; ">|</span><span style="color: gray; background: black; "> </span><span style="color: darkcyan; background: black; ">|/</span><span style="color: gray; background: black; ">                                                                                                                          </span><span style="color: black; background: black; "><br></span><span style="color: red; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">f5e91bb</span><span style="color: gray; background: black; "> change documentation                                                                                              </span><span style="color: black; background: black; "><br></span><span style="color: red; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">928d007</span><span style="color: gray; background: black; "> Mini changes on comments and doc                                                                                  </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: green; background: black; ">|</span><span style="color: gray; background: black; ">   </span><span style="color: #8b8b00; background: black; ">cac294e</span><span style="color: gray; background: black; "> Merge branches 'developpement' and 'master'                                                                     </span><span style="color: black; background: black; "><br></span><span style="color: yellow; background: black; ">|</span><span style="color: green; background: black; ">\</span><span style="color: gray; background: black; "> </span><span style="color: green; background: black; ">\</span><span style="color: gray; background: black; ">                                                                                                                          </span><span style="color: black; background: black; "><br></span><span style="color: yellow; background: black; ">|</span><span style="color: gray; background: black; "> </span><span style="color: green; background: black; ">|/</span><span style="color: gray; background: black; ">                                                                                                                          </span><span style="color: black; background: black; "><br></span><span style="color: yellow; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">6758b76</span><span style="color: gray; background: black; "> Append every properties on getproperties method                                                                   </span><span style="color: black; background: black; "><br></span><span style="color: yellow; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">c37fd35</span><span style="color: gray; background: black; "> Change file structure, src directory to put sources, and change setup.py to map modification                      </span><span style="color: black; background: black; "><br></span><span style="color: yellow; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">ff68e10</span><span style="color: gray; background: black; "> Remove class, this is better to use it as a simple module                                                         </span><span style="color: black; background: black; "><br></span><span style="color: yellow; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">f5f7de9</span><span style="color: gray; background: black; "> Finnaly, I don't like this properties (in fact, I didn't found how to do...)                                      </span><span style="color: black; background: black; "><br></span><span style="color: yellow; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">f31783b</span><span style="color: gray; background: black; "> Some test for Version and Sources properties on git                                                               </span><span style="color: black; background: black; "><br></span><span style="color: yellow; background: black; ">|</span><span style="color: gray; background: black; "> * </span><span style="color: #8b8b00; background: black; ">971b344</span><span style="color: gray; background: black; "> Changes documentation comments                                                                                    </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: blue; background: black; ">|</span><span style="color: gray; background: black; "> </span><span style="color: #8b8b00; background: black; ">21c5b31</span><span style="color: gray; background: black; "> Merge branches 'developpement' and 'master'                                                                       </span><span style="color: black; background: black; "><br></span><span style="color: blue; background: black; ">|/</span><span style="color: gray; background: black; ">                                                                                                                            </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: #8b8b00; background: black; ">1d4ae3b</span><span style="color: gray; background: black; "> Add quvi to C linker                                                                                                </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: #8b8b00; background: black; ">2ae25e0</span><span style="color: gray; background: black; "> the first code line was badly indented                                                                              </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: #8b8b00; background: black; ">8aa4027</span><span style="color: gray; background: black; "> Change README to "md" file that allows a pretty display on github                                                   </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: #8b8b00; background: black; ">28f0c02</span><span style="color: gray; background: black; "> The first README release                                                                                            </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: #8b8b00; background: black; ">398424c</span><span style="color: gray; background: black; "> append the setup.py file that compiles quvi.so, and install                                                         </span><span style="color: black; background: black; "><br></span><span style="color: gray; background: black; ">* </span><span style="color: #8b8b00; background: black; ">b69371c</span><span style="color: gray; background: black; "> first commit, inster pxd and pyx files                                                                              </span><span style="color: black; background: black; "><br></span></font>

Ça peut vous intéresser aussi


Git et les fichiers zip

Si un projet se base sur un fichier zip (pas ...


Gogs - le vrai clone de github

Vous trouvez gitlab lourd et pas facile à installer, je ...


Parlons de Git

Voilà que je me remets un peu au développement, question ...


Générer un graph pseudo UML PHP

Je vous ai parlé de mon petit outil, GTU (Graphlanguage ...

Merci de m'aider à financer mes services

Si vous avez apprécié cet article, je vous serai reconnaissant de m'aider à me payer une petite bière :)

Si vous voulez en savoir plus sur l'utilisation de flattr sur mon blog, lisez cette page: Ayez pitié de moi

Commentaires

Ajouter un commentaire

Ajouter un commentaire

(*) Votre e-mail ne sera ni revendu, ni rendu public, ni utilisé pour vous proposer des mails commerciaux. Il n'est utilisé que pour vous contacter en cas de souci avec le contenu du commentaire, ou pour vous prévenir d'un nouveau commentaire si vous avez coché la case prévue à cet effet.