git status - 列出上次修改日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14141344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:58:21  来源:igfitidea点击:

git status - list last modified date

git

提问by caitriona

Using git, is it possible to list an unstaged file's last modified date alongside it's path? using eg.

使用 git,是否可以在路径旁边列出未暂存文件的上次修改日期?使用例如。

git status

git status

or

或者

git diff --name-only

git diff --name-only

回答by fge

Not directly but you can use a pipe:

不直接,但您可以使用管道:

Note: original answer updated based on comments

注意:根据评论更新原始答案

Linux:

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

OSX(来源):

git status -s | while read mode file; do echo $mode $(stat -f "%m" $file) $file; done|sort

回答by VonC

Note: I needed to get the modified files sorted by date, so I modified the echo:

注意:我需要按日期排序修改后的文件,所以我修改了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.

通过首先回显日期 ( stat),然后回显文件,我能够从最旧到最新的修改进行排序。



Sam Hasleradds in the comments:

Sam Hasler在评论中补充道:

To preserve spacesin 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