Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git status - list last modified date

Tags:

git

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

like image 311
caitriona Avatar asked Jan 03 '13 14:01

caitriona


People also ask

How do you check who last modified a file in git?

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).

How can I tell when a git file was last updated?

If you want to see only the last change, you can use git log -p -1 -- b .

What is git status porcelain?

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.

How do I check my git status?

To check the status, open the git bash, and run the status command on your desired directory. It will run as follows: $ git status.


2 Answers

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
like image 196
fge Avatar answered Oct 08 '22 19:10

fge


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
like image 45
VonC Avatar answered Oct 08 '22 18:10

VonC