Created
April 27, 2017 22:52
-
-
Save wilsonmar/6bc073894a5cafd84c4954550361610d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# graph-dag.sh | |
# Draw a graphviz diagram of the Git DAG | |
# | |
# Labels consist of the short SHA1 and any refs. | |
# Unreachable commits (ignoring the reflog) will be marked with an asterisk and | |
# drawn with dashed lines. | |
# | |
# Largely stolen from https://git.wiki.kernel.org/index.php/ExampleScripts | |
# As seen on Seth House's videos at https://www.youtube.com/watch?v=AqDLz4yq_CI&index=1&list=PLA4B47B9B5F3691E3 | |
# | |
# Usage: | |
# git graph-dag HEAD~10.. | dot -Tpng | display -antialias | |
# | |
# Accepts any range or arguments that git rev-list accepts. | |
set -e | |
if [[ -z $@ ]] ; then | |
echo -e "Usage: git graph-dag HEAD~10.. | dot -Tpng | display -antialias" | |
exit 1 | |
fi | |
echo "digraph lattice {" | |
# Draw the DAG and connect parents | |
git rev-list --parents "$@" | | |
while read commit parents | |
do | |
for p in $parents | |
do | |
echo "n$commit -> n$p" | |
done | |
done | |
# Make pretty labels with the short sha1 and any refs | |
git rev-list --pretty=format:"%H %h %d" "$@" | awk ' | |
BEGIN { | |
command = "git fsck --unreachable --no-reflogs | cut -d\" \" -f3" | |
while (command | getline unr) unreachable[unr] = 1 | |
close(command) | |
} | |
!/^commit/ { | |
refs = "" | |
for (i=3; i<=NF; i++) refs = refs " " $i | |
unreachable[$1] == 1 ? isunr = 1 : isunr = 0 | |
printf "n%s [shape=Mrecord, style=%s, label=\"{%s%s}\"]\n", \ | |
$1, \ | |
isunr == 1 ? "dashed" : "filled", \ | |
isunr == 1 ? "*" $2 : $2, \ | |
refs == "" ? "" : refs | |
}' | |
echo "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment