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
176 views
in Technique[技术] by (71.8m points)

How to list files not tracked by git and sort them according to modification time?

I want to list the files that are not part of git repository and were recently modified. If there are no spaces in file names and git status returns only # before untracted files, then I can do:

ls -ltrhd `git status | awk 'NF==2 {print $2}'`

However, making this more universal (e.g., if there are spaces in file names), then it gets complicated. Is there a way to get the same output directly from git?

question from:https://stackoverflow.com/questions/65874736/how-to-list-files-not-tracked-by-git-and-sort-them-according-to-modification-tim

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

1 Answer

0 votes
by (71.8m points)

Is there a way to get the same output directly from git?

Nope. You can handle spaces in filenames by setting IFS though, and git status is doing some hidden recursing, to not do any of it you can use find's depth cutoff:

(IFS=$'
'; ls -ltrh $(git ls-files -o `find -maxdepth 1 ! -type d`))

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

...