Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

sorting - git ls-files sort by modification time

How can I list files sorted by their modification time?

I want the git modification time, not the system modification time. For example, if I have a (committed) file README, then

touch README

will change the system modification time... but the git status would remain unchanged.

If I try

git ls-files -z | xargs -0 ls  -t

this will sort by the system modification time.

Is there any option to git ls-files that would list files sorted by their git modification time?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Is there any option to git ls-files that would list files sorted by their git modification time?

I don't think so. One possible way would be to iterate over the files, get the timestamp using git log, and sort the output.

The following might work for you:

while read file; do echo $(git log --pretty=format:%ad -n 1 --date=raw -- $file) $file; done < <(git ls-tree -r --name-only HEAD) | sort -k1,1n

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...