开发者

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, 开发者_JAVA技巧grab the first result and use that for ordering.

Is there a better way?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜