List git files with last commit info
2025-06-12
Shows top-level files and directories in a git repo alongside their last commit hash, date, author, and message. Paginates with less if output exceeds 40 lines.
#!/bin/bash
output=$(git ls-tree --name-only HEAD | while read -r item; do
# Get the last commit affecting the item (which can be a file or a directory)
log=$(git log -1 --color=always \
--format='%C(yellow)%h%Creset %C(green)%ad%Creset %C(blue)%an%Creset %C(cyan)%s%Creset' \
--date=format:'%d.%m.%Y' -- "$item")
# Format the output line
printf "\033[1;34m%-30s\033[0m %s\n" "$item" "$log"
done)
# Count lines for pagination
lines=$(printf "%s\n" "$output" | wc -l)
# Paginate with 'less' if output is long
if [ "$lines" -gt 40 ]; then
printf "%s\n" "$output" | less -R
else
printf "%s\n" "$output"
fi