Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I know how to retrieve the last modification date of a single file in a git repository:

git log -1 --format="%ad" -- path/to/file

Is there a simple and efficient way to do the same for all the files currently present in the repository?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

A simple answer would be to iterate through each file and display its modification time, i.e.:

git ls-tree -r --name-only HEAD | while read filename; do
  echo "$(git log -1 --format="%ad" -- $filename) $filename"
done

This will yield output like so:

Fri Dec 23 19:01:01 2011 +0000 Config
Fri Dec 23 19:01:01 2011 +0000 Makefile

Obviously, you can control this since its just a bash script at this point--so feel free to customize to your heart's content!

share|improve this answer
1  
I was hoping that there was an option to get a combined output in a single run of git log, but your answer is better than the one I had in mind using find. I did not know git-ls-tree, which has the advantage of listing only the files stored in the repository, skipping the .git folder and ignored files. Thanks. –  Eric Bréchemier Jun 23 '12 at 8:25
    
No problem, Eric; you are following the same route that I did--i.e., doing a find and ignoring the .git directory! :) There may be some options using the git plumbing commands, but quite frankly, this works pretty well. If you could find some way to get the information on a per file basis all at once, that would work best--but remember, git operates on the state of commits, not the state of individual files. –  Andrew M. Jun 25 '12 at 16:40
    
Can this be adapted to work on a commit other than the current checkout HEAD? I think the log command is working relative to the HEAD here by default. –  ThorSummoner May 30 at 19:30
2  
I recommend using the --format="%ai" if you want sortable time stamps instead of human readable dates. –  ThorSummoner May 30 at 19:45
    
Since "HEAD" is just a reference, you can use any reference you want, be it a tag, branch, commit hash, etc.. –  Andrew M. May 30 at 23:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.