feat: Git `last-edits` alias
For each file, print the last commit datetime from the log of that file
and the name of the file, separated by a tab character and terminated by
a newline character. This can be used to easily find old/new files in a
repo by piping to sort --key=1
.
The alias supports git ls-tree
parameters.
The alias needs to be wrapped in a function because $@
is passed after
the alias command; it is not treated like a script
https://stackoverflow.com/a/3322412/96588.
Uses NUL-separated filenames to support as wide as possible types of
files. If you for some reason have newlines in your filenames, though,
the output will not be valid, and you'd need to wrap the command passed
to xargs
in either printf '%q\n'
to shell-quote the output or
printf '%s\0'
to output NUL-separated entries for further processing
before display. If there are any Git log format string special
characters (like %
) in any filenames, this will also break the output.
Forces datetime display in ISO-8859 format and a specific time zone (UTC, but could be anything) to ensure correct sorting. Otherwise it would be much harder to correctly sort the result.
I also tried with GNU Parallel, but that was ~10x slower on a large repository (https://github.com/NixOS/nixpkgs/, >530,000 commits, >37,000 files).
Inspired by https://serverfault.com/a/1031956/11292 and https://stackoverflow.com/a/3322412/96588.