-
Notifications
You must be signed in to change notification settings - Fork 6
GIT 获取文件最初创建及最新修改日期 #69
Copy link
Copy link
Closed
Labels
Description
需求描述
打算把自己的博客重构一下,想在每篇文章的页面中,显示该文章最初发表时间,和最后更新时间。上网找了找,又试了试,搞定了这个需求了。
实际代码
# 获取 git 仓库中所有文件的最新修改时间
$ git ls-tree -r --name-only HEAD | while read filename; do
> echo "$(git log -1 --pretty=format:"%ad" -- $filename) $filename";
> done
# 获取 git 仓库中所有文件的最初创建时间
$ git ls-tree -r --name-only HEAD | while read filename; do
> echo "$(git log --pretty=format:"%ad" -- $filename | tail -1) $filename";
> done参考资料
- https://git-scm.com/book/zh/v1/Git-基础-查看提交历史:介绍了
git log --pretty=format参数格式占位符的含义。 - How to retrieve the last modification date of all files in a git repository:介绍了如何获取 git 仓库中,所有文件的最新修改时间。
- Finding the date/time a file was first added to a Git repository:介绍了如何获取 git 仓库中,所有文件最初的创建时间。
Reactions are currently unavailable