我怎样才能看到在git上创建多个文件的日期? [英] How can I see the date multiple files were created on git?
本文介绍了我怎样才能看到在git上创建多个文件的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
<!c $ c>#!/ bin / bash
用于`git ls-files`中的文件
do
HASH =` git rev-list HEAD $ file | tail -n 1`
DATE =`git show -s --format =%ci$ HASH --`
printf%-35s%s\\\
%s\\\
$文件$ HASH:$ DATE
完成
/ b>
获取存储库中所有文件的列表
$ git ls-files
获取给定文件第一次提交的SHA-1:
$ git rev-list HEAD< file> | tail -n 1
这将返回一个给定文件的所有无父提交列表,按照时间倒序订购。最后一个是给定文件第一次提交的SHA-1哈希。
您可以通过运行 git whatchanged< hash> ;
。您应该看到如下所示:
commit< commit_hash>
作者:Susy Q< suzy@example.com>
日期:8月24日星期三12:36:34 2011 -0400
添加新模块'example.py'
:000000 100644 0000000 ...< hash> ... A example.py
显示给定提交的日期
$ git show -s --format =%ci< hash>
将它们放在bash脚本中:
<!c $ c>#!/ bin / bash
用于`git ls-files`中的文件
do
HASH =` git rev-list HEAD $ file | tail -n 1`
DATE =`git show -s --format =%ci$ HASH --`
printf%-35s%s\\\
%s\\\
$文件$ HASH:$ DATE
完成
I want to see the date of git creation (date of first commit where they were added) of all the files on a specified directory.
解决方案
I'll break my solution into steps.
Get a list of all files in the repository
$ git ls-files
This returns a list of relative paths of all files in the repository.
Get the SHA-1 of the first commit of a given file:
$ git rev-list HEAD <file> | tail -n 1
This will return a list of all parentless commits for a given file, in reverse chronological order. The last one is the SHA-1 hash of the first commit for the given file.
You can verify this by running git whatchanged <hash>
. You should see something like:
commit <commit_hash>
Author: Susy Q <suzy@example.com>
Date: Wed Aug 24 12:36:34 2011 -0400
Add new module 'example.py'
:000000 100644 0000000... <hash>... A example.py
Show the date of a given commit
$ git show -s --format="%ci" <hash>
Bringing it all together in a bash script:
#!/bin/bash
for file in `git ls-files`
do
HASH=`git rev-list HEAD $file | tail -n 1`
DATE=`git show -s --format="%ci" $HASH --`
printf "%-35s %s\n %s\n" $file $HASH: "$DATE"
done
这篇关于我怎样才能看到在git上创建多个文件的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文