The crux of the question, though, is do you want to see the file's last modification timestamp, or do you want to change the file's timestamp to what you think it should be (eg, the last modified time)? From the question, the OP seems to wish to see the file's timestamp, not necessarily manipulate it.
TL;DR: Just run this, and git ls
will show you last modified for all files in the pwd. NOTE: The $'
is part of the command, so copy the whole line
$'!cd -- ${GIT_PREFIX:-.};\nfor i in *; \ndo \n ls -ld $i | awk \'BEGIN { ORS="";} {print $1, $2, $3, $4; printf("%7s ",$5)}\'; \n gd=$(git log -1 --date=local --format="%ad" -- "$i"); \n [ -z "$gd" ] && gd=$(ls -ld "$i" | awk \'{print $6, $7, $8}\'); \n if [ $(date -d "$gd" +%s) -le $(date -d "6 months ago" +%s) ] ; \n then dfmt=\'%b %_d %Y\'; \n else dfmt=\'%b %_d %H:%M\'; \n fi; \n echo -n "$(date -d "$gd" +"$dfmt") "; \n ls -d --color=always "$i"; \ndone'
For me, I just want to see the last modified date, not go mucking around with actual timestamps on the filesystem.
So, I bothered to write a bash script that gives me an ls
-style output that displays the git repo's last modified date (ie, the author's timestamp) instead of the timestamp on disk. It's a rather rough cut, but it works the way I want it to.
cd -- ${GIT_PREFIX:-.};
for i in *;
do
ls -ld $i | awk 'BEGIN { ORS="";} {print $1, $2, $3, $4; printf("%7s ",$5)}';
gd=$(git log -1 --date=local --format="%ad" -- "$i");
[ -z "$gd" ] && gd=$(ls -ld "$i" | awk '{print $6, $7, $8}');
if [ $(date -d "$gd" +%s) -le $(date -d "6 months ago" +%s) ] ;
then dfmt='%b %_d %Y';
else dfmt='%b %_d %H:%M';
fi;
echo -n "$(date -d "$gd" +"$dfmt") ";
ls -d --color=always "$i";
done
Save this file as, eg, your ~/scripts/git-ls. Assuming that's the path you use, then import in into your git config with
echo "git config --global alias.ls $(printf '%q' "`echo -n \!; cat ~/scripts/git-ls`")" | bash -
It builds the git config
command, and then hands it off to a bash sub-shell to execute it.
Pros:
- It displays all files - even ones not in the repo
- It looks exactly like a standard
ls
output
- It preserves the file colors I want
- I can edit (and test) the script by running ~/scripts/git-ls directly
git help ls
still shows the definition as a readable script
Cons:
- It is inefficient; you see the output scroll
- "It's not a bug - it's a feature!"... Well, it makes it obvious whether you ran
git ls
or just plain ls
- It doesn't handle any arguments
- Not file globs, but output can be piped to
grep
- Not any flags to
ls