This is git log
for cool kids: Quick Demo
- Run in your terminal
gli
to invoke the function. - To do a fuzzy search, just start typing.
- To view all changes in fullscreen, highlight a commit and press
ENTER
, pressq
to exit fullscreen. - To copy a commit hash to your clipboard, press
CTRL-C
. - To exit the function, press
ESC
.
Note: This function uses fzf and diff-so-fancy, make sure they're both installed.
- Navigate to your root directory with
cd ~
. - Open your
.zshrc
file withnano .zshrc
. - Copy and paste the shell function at the bottom of the file:
function gli() {
local git_log_line_to_hash="echo {} | grep -o '[a-f0-9]\{7\}' | head -1"
local view_git_log_line="${git_log_line_to_hash} | xargs -I % sh -c 'git show --color=always % | diff-so-fancy'"
git log \
--color=always \
--format="%C(cyan)%h %C(blue)%ar%C(auto)%d %C(yellow)%s%+b %C(black)%ae" "$@" | \
fzf -i -e +s \
--reverse \
--tiebreak=index \
--no-multi \
--ansi \
--preview="${view_git_log_line}" \
--header "ENTER: View in pager, CTRL+C: Copy hash" \
--bind "enter:execute:${view_git_log_line} | less -R" \
--bind "ctrl-c:execute:${git_log_line_to_hash} | pbcopy"
}
- To save the file, press
CTRL-X
, thenY
, thenENTER
. - Apply the changes with
source ~/.zshrc
.
Note: If you're using bash, follow the same steps but replace
.zshrc
with.bashrc
.