gitgraph() { gitdir=. while [ ! -d "$gitdir"/.git -a ! -d "$gitdir"/proc ]; do gitdir="$gitdir/.." done regex="" sel="$@" if [ "$sel" = "" ]; then sel="" if [ -s .git/HEAD ]; then sel="HEAD $sel"; fi if [ -s .git/ORIG_HEAD ]; then sel="ORIG_HEAD $sel"; fi if [ -s .git/FETCH_HEAD ]; then sel="FETCH_HEAD $sel"; fi if [ -s .git/MERGE_HEAD ]; then sel="MERGE_HEAD $sel"; fi if false; then sel="`git rev-parse --all $sel | git name-rev --stdin --name-only|sort|uniq`" else sel="`git rev-parse --symbolic --all $sel`" newsel="" for s in $sel; do # Last word: #sim1="`echo "$s"|sed 's@.*/@@'`" # Last two words: #sim2="`echo "$s"|perl -pe 's@.*/([^/]*/)@\1@'`" # Second-last word: #sim2b="`echo "$s"|perl -pe 's@.*/([^/]*)/[^/]*$@\1@'`" # sim2 = ignore first 2 words sim2="`echo "$s"|perl -pe 's@^[^/]*/[^/]*/@@'`" # sim2b = ignore first 2 word and the last word sim2b="`echo "$sim2"|perl -pe 's@/[^/]*$/@@'`" #echo -e "s($s)\tsim1($sim1)\tsim2($sim2)\tsim2b($sim2b)" t="$s" case "$s" in refs/tags/*) t="$sim2" ;; refs/heads/*) if [ ! -f .git/refs/tags/$sim2 ]; then t="$sim2" else t="heads/$sim2" fi ;; refs/remotes/*/HEAD) if [ ! -f .git/refs/tags/$sim2b \ -a ! -f .git/refs/heads/$sim2b ]; then t="$sim2b" else t="remotes/$sim2b" fi ;; refs/remotes/*/*) t="$sim2" ;; refs/remotes/*) #if [ ! -f .git/refs/tags/$sim1 \ # -a ! -f .git/refs/heads/$sim1 ]; then # t="$sim1" #else # t="remotes/$sim1" #fi ;; *) ;; esac #echo "s($s)1($sim1)2($sim2)2b($sim2b) Made($t)" newsel="$newsel $t" done sel="$newsel" fi if [ -f .git/refs/stash ]; then # Add all stash refs sel="$sel `git log --no-color --pretty=oneline -g stash|tail -n +2|perl -pe 's/^[^ ]* *//;s/:.*//'`" fi fi #sel="$sel `git log --no-color --pretty=oneline -g HEAD|perl -pe 's/^[^ ]* *//;s/:.*//'`" for s in $sel; do #sha1="`git rev-parse "$s"`" #sha1="`git log "$s" -1 --pretty='format:%H'`" # rev-parse fails to display commit id for tags sha1="`git rev-parse "$s"'^0'`" s="`echo "$s"|sed 's/{/\\\\{/g'`" regex="$regex;s!(${sha1:0:7})!\1 <$s>!" done #git log --no-color --pretty=oneline -g stash \ # | perl -pe 's/^(.{7})[^ ]* (.*?):.*/@(\1)@\\1 <\2>@/' \ # | while read s; do # regex="$regex;$s" # done #echo "$regex" git log $sel --graph --pretty='format:%h %ai %s' --full-history --simplify-merges \ | perl -pe "$regex" |less }