Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: how to list all files under version control along with their author date?

Tags:

git

Given a git repo, I need to generate a dictionary of each version controlled file's last modified date as a unix timestamp mapped to its file path. I need the last modified date as far as git is concerned - not the file system.

In order to do this, I'd like to get git to output a list of all files under version control along with each file's author date. The output from git ls-files or git ls-tree -r master would be perfect if their output had timestamps included on each line.

Is there a way to get this output from git?

Update for more context: I have a current implementation that consists of a python script that iterates through every file under source control and does a git log on each one, but I'm finding that that doesn't scale well. The more files in the repo, the more git log calls I have to make. So that has led me to look for a way to gather this info from git with fewer calls (ideally just 1).

like image 204
derekvanvliet Avatar asked Oct 03 '13 18:10

derekvanvliet


1 Answers

a list of all files under version control along with each file's author date

Scaling isn't a problem with this one:

#!/bin/sh
temp="${TMPDIR:-/tmp}/@@@commit-at@@@$$"
trap "rm '$temp'" 0 1 2 3 15
git log --pretty=format:"%H%x09%at" --topo-order --reverse "$@" >"$temp"
cut -f1 "$temp" \
| git diff-tree -r --root --name-status --stdin \
| awk '
        BEGIN {FS="\t"; OFS="\t"}
        FNR==1{++f}
        f==1  {at[$1]=$2; next}
        NF==1 {commit=$1; next}
        $1=="D"{$1=""; delete last[$0]; next} # comment to also show deleted files
              {did=$1;$1=""; last[$0]=at[commit]"\t"did}
        END   {for (f in last) print last[f]f}
 ' "$temp" - \
| sort -t"`printf '\t'`" -k3
like image 101
jthill Avatar answered Oct 14 '22 01:10

jthill