tags:

views:

50

answers:

1

Is there a simple git command to determine the "creation date" of a file in a repository, i.e. the date it was first added? It would be best if it can determine this even through file renames/moves.

I'd like it to be a computer-readable one-line output; it may be that I haven't figured out the correct git log <fname> options to do this.

+2  A: 

git log --format=%aD <FILE> | tail -1

With this command you can out all date about this file and extract the last

shingara
You'll also need `--follow` to follow the log through renames as the OP asked. Also good practice to add `--` before the filename just in case it clashes with an option or ref name.
Steve Folly
Since I was planning on calling `git` from Python, I was hoping for a command that doesn't require piping. I suppose I can just get the final line with Python, though. Any thoughts? Thanks!
Seth Johnson
@Seth: you could use `subprocess.Popen` and `communicate()` to read stdout into a string. Split the string on \n into a list, then get element -1. Check out http://docs.python.org/library/subprocess.html#popen-objects
Steve Folly
@Steve Folly: I meant that I knew how to use subprocess and `some_string.split('\n')[-1]`, but I was asking for thoughts on getting Git to return only the first log entry.
Seth Johnson
Actually, since git leaves a trailing newline, you have to do [-2].
Seth Johnson