If I do git status
I see a bunch of changed files and a few new ones as well. I'd like to be able to see the last modified time of each of these files (and from there see which one is the oldest / newest) but it is not clear to me how to do that. Any ideas?
Asked
Active
Viewed 892 times
1

neubert
- 15,947
- 24
- 120
- 212
-
1You want to see what time exactly? The time of the commit that last modified the files or the time the file was modified since the most recent commit (the modification that causes it to show in the `git status` output)? Some other time? – Etan Reisner Jun 24 '15 at 01:20
-
If you do `ls -latr` it shows a last modified time. Since I'm only wanting to see it for new or modified files that haven't been added or committed I guess it'd be the time the file was modified since the most recent commit. – neubert Jun 24 '15 at 01:24
-
So you want the filesystem modification time of each file listed in the `git status` output? – Etan Reisner Jun 24 '15 at 01:29
2 Answers
2
Committed File Information
git ls-tree -r --name-only HEAD | while read filename; do
echo "$(git log -1 --format="%ad" -- $filename) $filename"
done
Modified Files without commit Information
git status --porcelain | awk {'print $2'} | while read filename; do
echo -n $filename ' ' ; stat $filename | grep Modify;
done

Leandro Papasidero
- 3,728
- 1
- 18
- 33
-
This `echo` should probably be a `printf` but that's not a big deal. This is also the date of the most recent commit that modified that modified the file and not the date/time of the current modification that made the file be listed in `git status`. – Etan Reisner Jun 24 '15 at 10:55
1
There is surely a better way, but a method which works is
$ git ls-files --debug
yaml_parse.py
ctime: 1434026542:225611371
mtime: 1433442706:0
dev: 34 ino: 17436117
uid: 33156 gid: 4720
size: 5065 flags: 0
$ cvttime 1433442706
1433442706 = 2015-06-04 Thu 18:31:46 +0000 (UTC)

wallyk
- 56,922
- 16
- 83
- 148
-
For people scratching their heads about `cvttime`: it seems to be an `awk(1)` function defined in [this post](http://stackoverflow.com/a/20308202/4959010). Another `perl` version of it might look like this: `perl -E 'say scalar localtime shift' 1433442706`. – Sato Katsura Jun 24 '15 at 03:56