Using git, is it possible to list an unstaged file's last modified date alongside it's path? using eg.
git status
or
git diff --name-only
Git doesn't record the last modification date, only the commit/author dates for a all commit (which can include more than one file). You would need to run a script in order to amend a commit with the last modification date of a particular file (not very useful if said commit has more than one file in it).
If you want to see only the last change, you can use git log -p -1 -- b .
Porcelain Format Version 1 Version 1 porcelain format is similar to the short format, but is guaranteed not to change in a backwards-incompatible way between Git versions or based on user configuration. This makes it ideal for parsing by scripts.
To check the status, open the git bash, and run the status command on your desired directory. It will run as follows: $ git status.
Not directly but you can use a pipe:
Note: original answer updated based on comments
Linux:
git status -s | while read mode file; do echo $mode $file $(stat -c %y $file); done
Windows:
git status -s | while read mode file; do echo $mode $(date --reference=$file +"%Y-%m-%d %H:%M:%S") $file; done
OSX (source):
git status -s | while read mode file; do echo $mode $(stat -f "%Sm" $file) $file; done|sort
Note: I needed to get the modified files sorted by date, so I modified the echo:
git status -s | while read mode file; \
do echo $mode $(stat -c %y $file) $file; \
done|sort -k1,4
One line:
git status -s | while read mode file; do echo $mode $(stat -c %y $file) $file; done|sort -k1,4
By echoing first the date (stat
), and then the file, I was able to sort from oldest to newest modification.
Sam Hasler adds in the comments:
To preserve spaces in mode:
IFS=''; git status -s | while read -n2 mode; read -n1; read file; do echo $mode $(stat -c %y "$file") $file; done|sort
That is:
IFS=''; git status -s | while read -n2 mode; read -n1; read file; \
do echo $mode $(stat -c %y "$file") $file; \
done|sort
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With