Skip to content

Instantly share code, notes, and snippets.

@KathyBarabash
Forked from niun/set-pretty-git-log-alias.sh
Last active December 13, 2023 09:48
Show Gist options
  • Save KathyBarabash/3dfcfb2df457a7f4a6a5962ffd06b4a3 to your computer and use it in GitHub Desktop.
Save KathyBarabash/3dfcfb2df457a7f4a6a5962ffd06b4a3 to your computer and use it in GitHub Desktop.
git log graph --oneline with date and author and colored ref names as alias
## One line per log entry with merge graph
## (--decorate is implicit for newer git versions?):
#git log --graph --oneline --decorate
## |
## Add --branches --remotes --tags --merges to see entries for all of the
## corresponding refs, not only commits (--all for all refs).
## Format output with --pretty=tformat:'<format>'
## Interesting placeholders for oneline <format>:
## %h hash (abbreviated)
## %d refs (like remotes, branches, tags + HEAD) in Paratheses (%D without).
## %s subject (tilte of commit message)
## %ad date given by --date=<format>. %ar is relative date (like "4 days ago")
## %an author name. %aN is autor name in respect of .mailmap file with aliases
## %Cred, %Cgreen, %Cblue start color. %Creset stop color.
## %C(<color>) color defined in config. %C(auto) auto color, useful for e.g. %d
## basic "git log --oneline":
#git log --pretty=tformat:'%C(auto)%h%d %s'
# git alias configuration:
# declare "git la" alias with relative date and author
# => <sha1> (<ref names>) <title> (<relative date> by <author>)
git config --global alias.la "log --all --graph --pretty=format:'%C(auto)%h%d %s %C(bold black)(%ar by <%aN>)%Creset'"
# declare "git law" alias same as "git la" but with lines wrapped
git config --global alias.law "log --all --graph --pretty=format:'%C(auto)%h%d %w(100,0,8)%s %C(bold black)(%ar by <%aN>)%Creset'"
# declare "git lad" alias with leading short-iso-like date and trailing author
# => <date> <sha1> (<ref names>) <title> <author>
git config --global alias.lad "log --all --graph --pretty=format:'%Cgreen%ad%Creset %C(auto)%h%d %s %C(bold black)<%aN>%Creset' --date=format-local:'%Y-%m-%d %H:%M (%a)'"
## More oneline examples:
#git log --all --graph --pretty=format:'%C(auto)%h -%d %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'
#git log --all --graph --pretty=format:"%ad %C(yellow)%h%Creset %s %Cblue[%an]" --date="format-local:%a %Y-%m-%d %H:%M"
git log --all --graph --pretty=format:"%C(yellow)%h%Creset -%C(auto)%d %C(green)%ad%Creset %s %Cblue<%an>" --date="format-local:%a %Y-%m-%d %H:%M"
git log --all --graph --pretty=format:"%C(yellow)%h%Creset%C(auto)%d %C(green)%ad%Creset %s %C(blue)<%an>" --date="format-local:%d.%m.%Y %H:%M"
git log --format="tformat:%>|(15)%C(auto)%h %Cgreen %<(20,trunc)%cn %C(auto) %<(15,trunc)%ar %<($(($(tput cols)-55)),trunc)%s" --graph --all
git log --format="tformat:%>|(18)%C(auto)%h%<($(($(tput cols)-110)),trunc)%C(auto)%d %<($(($(tput cols)-100)),trunc)%s %Cgreen%<(15,trunc)%cn %C(blue)%<(16,trunc)%ad%Creset" --graph --all --date="format-local:%d.%m.%Y %H:%M"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment