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
@sastorsl
Copy link

To not have to handle filenames at all in references one can use the object SHA.

Also sending the output to a file for easy sorting and search without having to run the same query many times.

git ls-tree -r HEAD | head | while read MODE TYPE SHA FILENAME; do
  echo $(git log -1 --all --find-object=${SHA} --format="%ad | %h | %an <%ae> |" --date=iso-strict) "${FILENAME}"
done | tee tmpfile.txt

Sort and search

# oldest last
sort -r tmpfile.txt

# find a specific file
grep gitignore tmpfile.txt

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