Skip to content

Latest commit

 

History

History
139 lines (86 loc) · 3.73 KB

index.adoc

File metadata and controls

139 lines (86 loc) · 3.73 KB

URLs

Tip
Do you want to improve this page? Please git-edit it on GitHub, edit.

Motivation

Drawing Git Diagram is very important to explain a branching model, or how a tool works, or the required commits during a release process.

Drawing such diagrams manually is really boring. Especially when you need multiple steps of the same git diagram: you often need to redo the same modifications (like changing a color or a label) on multiple pictures.

The Diagrams.net (formally Draw.io) project has shared an article about how to draw a git flow diagram.

This project automates the creation of such a diagram. Instead of drawing you defines your commits and the branches you would like to have and you generate the picture.

In addition the tool also supports additional outputs than draw.io.

Examples page

Check the examples page to see different possibilities and different outputs.

Usage

The code shared in this project is a prototype more than a real library.

To use it, the best is to have a look at the tests that creates the images in the git-examples folder.

Java code to create a diagram:

link:../../test/java/fr/jmini/gitgraph4j/DiagTestUtil.java[role=include]

link:../../test/java/fr/jmini/gitgraph4j/AbstractTestCreateDiagram.java[role=include]

Drawio

Out of this the tool is computing the drawio source xml which can then be turn into a svg or a png picture:

graph.drawio

This is the primary target output of the tool.

Mermaid JS

Mermaid JS has a module specialized in drawing git graphs.

The graph corresponding to the previous example would be:

link:examples/diag06/graph.mmd[role=include]

Which is rendered like this:

link:examples/diag06/graph.mmd[role=include]

Not everything that can be defined in the Java code is properly mapped to the mermaid syntax

Dot / Graphviz

The git graph can be turned into a Graphviz file (*.gv), written using the DOT description language

The graph corresponding to the previous example would be:

link:examples/diag06/graph.gv[role=include]

Which is rendered like this:

link:examples/diag06/graph.gv[role=include]

Control commits order

Sometimes you want to control the commits order. In this case it is better to add the commits directly to the diagram:

link:../../test/java/fr/jmini/gitgraph4j/DiagramTest.java[role=include]

When the diagram holds all the commits (no other commits added only on one of the contained branches), then no algorithm to sort the commits is applied.

Download

The code is not hosted on maven central. If you want to use it, the best option is to clone the repo and to run it locally.

Build

This project is using gradle.

Command to build the sources locally:

./gradlew build

Command to build the documentation page:

./gradlew asciidoctor

The output of this command is an HTML page located at <git repo root>/build/docs/html5/index.html.