Format Strings
%H: commit hash
%h: abbreviated commit hash
%T: tree hash
%t: abbreviated tree hash
%P: parent hashes
%p: abbreviated parent hashes
%an: author name
%aN: author name (respecting .mailmap, see
git-shortlog(1) or
git-blame(1))
%ae: author email
%aE: author email (respecting .mailmap, see
git-shortlog(1) or
git-blame(1))
%ad: author date (format respects --date= option)
%aD: author date, RFC2822 style
%ar: author date, relative
%at: author date, UNIX timestamp
%ai: author date, ISO 8601 format
%cn: committer name
%cN: committer name (respecting .mailmap, see
git-shortlog(1) or
git-blame(1))
%ce: committer email
%cE: committer email (respecting .mailmap, see
git-shortlog(1) or
git-blame(1))
%cd: committer date
%cD: committer date, RFC2822 style
%cr: committer date, relative
%ct: committer date, UNIX timestamp
%ci: committer date, ISO 8601 format
%d: ref names, like the --decorate option of
git-log(1)
%e: encoding
%s: subject
%f: sanitized subject line, suitable for a filename
%b: body
%B: raw body (unwrapped subject and body)
%N: commit notes
%gD: reflog selector, e.g., refs/stash@{1}
%gd: shortened reflog selector, e.g., stash@{1}
%gs: reflog subject
%Cred: switch color to red
%Cgreen: switch color to green
%Cblue: switch color to blue
%Creset: reset color
%C(…): color specification, as described in color.branch.* config option
%m: left, right or boundary mark
%n: newline
%%: a raw %
%x00: print a byte from a hex code
%w([[,[,]]]): switch line wrapping, like the -w option of
git-shortlog(1).
Show git branches available:
git branch
Show all branches including remote branches:
git branch -a
Create new branch:
git branch new_branch
Change branches:
git checkout new_branch
Delete branch:
git branch -d new_branch
# delete only if all changes are merged
git branch -D new_branch
# delete even if there are unmerged changes
Merge branch into current copy:
git merge --no-ff branch_to_merge_in
Resolve a Merge:
1) Edit file to resolve
2) git add conflict_file
3) git commit
Using Mergetool
git mergetool
git mergetool --tool=meld
git mergetool -t meld
Abort a merge conflict before committing:
git merge --abort
Undo a Merge: # restores state to pre-merge
git reset --heard HEAD
Undo a local commit:
git reset --soft HEAD^
Find the commit where two branches diverge:
git merge-base branch1 branch2
http://stackoverflow.com/questions/1549146/find-common-ancestor-of-two-branches
Find what branches were merged into a given branch:
git branch --merged master
# local branches only
git branch -a --merged master
# local and remote branches
Find what branches were NOT merged into a given branch:
git branch --no-merged master
# local branches only
git branch -a --no-merged master
# local and remote branches
Find what branches are merged into develop, but not master:
comm -12 <(sort <(git branch -a --no-merged origin/master)) <(sort <(git branch -a --merged origin/develop))
https://stackoverflow.com/questions/8071079/git-list-branches-merged-into-a-branch-but-not-into-another
Copy all branches from origin to new_remote:
git push new_remote refs/remotes/origin/*:refs/heads/*
Get number of commits per author
apt-get install git-extras