from Hacker News

Everyday Git Aliases

by joejag on 4/7/13, 9:32 PM with 3 comments

  • by Flenser on 4/8/13, 8:47 AM

    git staged

    alias for

        git log remotes/trunk~4..HEAD --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s" --date=short | awk -F'\t' '{gsub(/[, ]/,"",$2);gsub(/HEAD/, "\033[1;36mH\033[00m",$2);gsub(/master/, "\033[1;32mm\033[00m",$2);gsub(/trunk/, "\033[1;31mt\033[00m",$2);print $1 "\t" gensub(/([\(\)])/, "\033[0;33m\\1\033[00m","g",$2) $3}' | less -eiFRXS
    
    Shows condensed log of unpushed changes with colours and truncates HEAD/master/remote to initial letter.

    Add to config with:

        git config alias.staged '!git log remotes/trunk~4..HEAD --date=short --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s" | awk -F"\t" "{gsub(/[, ]/,\"\",\$2);gsub(/HEAD/, \"\033[1;36mH\033[00m\",\$2);gsub(/master/, \"\033[1;32mm\033[00m\",\$2);gsub(/trunk/, \"\033[1;31mt\033[00m\",\$2);print \$1 \"\t\" gensub(/([\(\)])/, \"\033[0;33m\\\\\1\033[00m\",\"g\",\$2) \$3}"'
    
    
    Although I've changed it a bit since I worked out the above. Here's what I currently have in my config file:

        	staged = "!sh -c 'git log ${1-remotes/trunk~4..HEAD} --pretty=format:\"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s\" --date=short $2 | awk -F\"\\t\" \"{gsub(/[, ]/,\\\"\\\",\\$2);gsub(/HEAD/, \\\"\\033[1;36mH\\033[00m\\\",\\$2);gsub(/master/, \\\"\\033[1;32mm\\033[00m\\\",\\$2);gsub(/trunk/, \\\"\\033[1;31mt\\033[00m\\\",\\$2);gsub(/$USERNAME/,\\\"\\033[0;33m$USERNAME\\033[00m\\\",\\$1);print \\$1 \\\"\\t\\\" gensub(/([\\(\\)])/, \\\"\\033[0;33m\\\\\\\\\\1\\033[00m\\\",\\\"g\\\",\\$2) \\$3}\" | less -eiFRX' -"
  • by joejag on 4/7/13, 9:32 PM

    I'd love to hear what aliases other people use in their workflow
  • by joshguthrie on 4/8/13, 9:43 AM

    whoiswinning

        $ alias whoiswinning
        whoiswinning='git shortlog -s -n'
        $