简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM