Skip to content

Instantly share code, notes, and snippets.

@mixu
Created September 4, 2014 21:02
Show Gist options
  • Select an option

  • Save mixu/dbca40ec642ee652136e to your computer and use it in GitHub Desktop.

Select an option

Save mixu/dbca40ec642ee652136e to your computer and use it in GitHub Desktop.
Find oldest files in a git repo
git ls-tree -r --name-only HEAD | while read filename; do
echo "$(git log -1 --format="%at | %h | %an | %ad |" -- $filename) $filename"
done
@ozh
Copy link

ozh commented Dec 20, 2025

Impractical on large repo with more than a couple dozen files, too slow. Muuuch faster:

git log --name-only --date=iso --format="%ad" --reverse | \
awk -v files="$(git ls-tree -r --name-only HEAD | tr '\n' '|')" '
BEGIN {
    gsub(/\|$/, "", files)
    split(files, arr, "|")
    for (i in arr) current[arr[i]] = 1
}
/^[0-9]{4}-/ {date=$0; next}
NF && current[$0] {last[$0] = date}
END {for (file in last) print last[file] " | " file}
' | sort -r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment