nickf
nickf

Reputation: 546035

How to find the date of the first commit of files in git

Would there be a way to see the date of the first commit of a list of files, such that I could order them by that list?

For context, I'm playing around with Node.JS, using it to create a simple blog where the "database" is actually a git repository.

What I thought I'd try is to list out all the files in a particular directory, and then call something like this on each:

git log --format="format:%ci" --reverse [my file here]

This would output something like this:

2010-09-01 11:42:56 -0700
2010-09-22 12:17:19 -0700
2010-09-22 13:18:11 -0700
2011-03-05 00:11:19 -0800
2011-08-26 08:50:02 -0700
2011-08-26 08:51:50 -0700

Then, grab the first result and use that for ordering.

Is there a better way?

Upvotes: 6

Views: 3268

Answers (1)

Mark Longair
Mark Longair

Reputation: 467201

I think you can get what you want using the --diff-filter option to git log, selecting only files that have been added. For example, you could parse the output of:

git log --format="format:%ci" --name-only --diff-filter=A

See the documentation for git log for more on the different states understood by --diff-filter.

Upvotes: 9

Related Questions