git status - list last modified date

后端 未结 2 630
孤街浪徒
孤街浪徒 2020-12-24 05:47

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 -

相关标签:
2条回答
  • 2020-12-24 06:16

    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
    
    0 讨论(0)
  • 2020-12-24 06:18

    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 "%m" $file) $file; done|sort
    
    0 讨论(0)
提交回复
热议问题