简体   繁体   English

如何在git中找到第一次提交文件的日期

[英]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. 对于上下文,我正在使用Node.JS,使用它创建一个简单的博客,其中“数据库”实际上是一个git存储库。

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. 我认为你可以使用--diff-filter选项获取你想要的--diff-filtergit log ,只选择已经添加的文件。 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 . 有关--diff-filter理解的不同状态的更多信息,请参阅git log文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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