Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...