List last commit dates for a large number of files, quickly

后端 未结 4 1989
攒了一身酷
攒了一身酷 2021-01-04 03:10

I would like to list the last commit date for a large number of files in a git repository.

For the sake of concreteness, let us assume that I want t

4条回答
  •  时光说笑
    2021-01-04 03:30

    I'm somewhat late to the party here, but here's a little Bash script that uses the invocation in OP's #2, and does the postprocessing in awk. (For my use, I didn't need to see files that had gotten deleted as of the current date, so there's the existence check too.)

    #!/bin/bash
    (
        git ls-files | sed 's/^/+ /'
        git log --format=format:"~ %aI" --name-only .
    ) | gawk '
    /^~/ {date=$2;}
    /^+/ {extant[$2] = 1;}
    /^[^~+]/ {dates[$1] = date;}
    END { for (file in dates) if(extant[file]) print(dates[file], file); }
    ' | sort
    

提交回复
热议问题