Skip to content

Instantly share code, notes, and snippets.

@debiru
Created August 6, 2022 14:19
Show Gist options
  • Save debiru/36b580938e97622d06ce92638e9425f2 to your computer and use it in GitHub Desktop.
Save debiru/36b580938e97622d06ce92638e9425f2 to your computer and use it in GitHub Desktop.
複数ファイルに対して `git log -n 1 --pretty=format:%cs` をファイルごとに実行せずに高速に最終コミット日時を得る方法
#!/bin/bash
cd $(dirname $0)
if [ $# -ge 1 ]; then
cd "$1" || exit
else
echo "Usage: $0 /path/to/repo/dir" && exit
fi
lines=$(git log --pretty=format:%cs --name-only --reverse .)
declare -A map
date=''
IFS=$'\n'
for line in $lines; do
if [[ $line =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
date="$line"
else
map[$line]="$date"
fi
done
for key in "${!map[@]}"; do
echo -e "${key}\t${map[${key}]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment