Skip to content

Instantly share code, notes, and snippets.

@techgaun
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save techgaun/04ad6000a03b581803ac to your computer and use it in GitHub Desktop.

Select an option

Save techgaun/04ad6000a03b581803ac to your computer and use it in GitHub Desktop.
Collection of miscellanous git tips

Collection of miscellanous git tips

Get current branch

git rev-parse --abbrev-ref HEAD
git symbolic-ref --short HEAD #probably works for 1.8 and newer clients

Get Author Information

git --no-pager show -s --format='%ae' COMMIT_HASH #get author e-mail
git --no-pager show -s --format='%an <%ae>' COMMIT_HASH #get author name and e-mail in user <email> format

Get last commit hash

git rev-list --max-count=1 HEAD
git log -n 1 --pretty=format:"%H"
git --no-pager show -s --format='%H'

git-blame a directory (what you see on repos view)

Have the following script with executable permission anywhere based on $PATH

#!/bin/bash

format='%Cblue%h%Creset %s%x09%ar'
git ls-tree --name-only -z HEAD |
while IFS= read -d '' file; do
git log -1 --pretty="$file"$'\t'"$format" -- "$file"
done |
column -t -s $'\t'

Author

samar[at]techgaun[dot]com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment