-
-
Save mixu/dbca40ec642ee652136e to your computer and use it in GitHub Desktop.
| git ls-tree -r --name-only HEAD | while read filename; do | |
| echo "$(git log -1 --format="%at | %h | %an | %ad |" -- $filename) $filename" | |
| done |
Nice script!
FWIW: the $filename of the git log command needs to be quoted with double quotes, otherwise the command will fail for files with spaces in the pathname and you will get only the filename without the timestamp:
git ls-tree -r --name-only HEAD | while read filename; do
echo "$(git log -1 --date=iso --format="%ad |" -- "$filename") $filename"
doneSee the following example:
~/example$ tree
.
βββ foo bar baz.txt
0 directories, 1 filewithout quotes
~/example$ git ls-tree -r --name-only HEAD | while read filename; do echo "$(git log -1 --date=iso --format="%ad |" -- $filename) $filename" ; done
foo bar baz.txtwith quotes
~/example$ git ls-tree -r --name-only HEAD | while read filename; do echo "$(git log -1 --date=iso --format="%ad |" -- "$filename") $filename" ; done
2022-11-11 16:39:49 +0100 | foo bar baz.txtUnfortunately, it also fails with non-ascii characters in the filename:
~/example$ tree
.
βββ Γ€_ΓΆ_ΓΌ.txt
βββ foo bar baz.txt
0 directories, 2 files~/example$ git ls-tree -r HEAD
100644 blob 924665ce4c939bd9fdbfec512cdf379f0c8696c4 foo bar baz.txt
100644 blob 6718a7cf7fb4f41ea7ed4aefad5dd1946a9bb2b4 "\303\244_\303\266_\303\274.txt"If you want to handle cases where a file has been renamed but not otherwise modified since (and in those cases see the time stamp before the rename), add:
--follow --diff-filter=r
This looks for renames (--follow), then filters them out (lower-case r).
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.txtSort and search
# oldest last
sort -r tmpfile.txt
# find a specific file
grep gitignore tmpfile.txt
Thanks @vielmetti, this is exactly what I was looking for. π