bash - How to list the original commits (time and author) per file of a directory with git?
问题描述
I want to use git to list me (in ls
-style):
- Who was the original author of that file
- When the file was created
I'm looking for a output like this:
File Original Author First Added Commit
----------------------------------------------------------------
a.yaml tom 01/01/2020 1a12121
b.yaml felix 05/01/2020 ad12257
[...]
Is his somehow possible with git?
解决方案
You can use git log --pretty-format
and --diff-filter=A
(A
for added):
#!/bin/bash
echo "File Original Author First Added Commit"
echo "----------------------------------------------------------------"
if [[ $# -eq 0 ]]; then
# No arguments, list all in current directory
files=(*)
else
# Only show those supplied on the command line
files=("$@")
fi
for file in "${files[@]}"
do
if [[ -f $file ]]; then
msg=$(git log --diff-filter=A --pretty=format:'%al %as %h' "$file")
printf "%-17s %-20s %-17s %s\n" "$file" $msg
fi
done
Example:
File Original Author First Added Commit
----------------------------------------------------------------
CMakeLists.txt ted 2020-06-24 41b5c92
LICENSE ted 2019-06-25 39d3ad5
README.md ted 2019-06-25 0bfa2a3
TODO ted 2020-01-13 aaeea10
--pretty-format
supports a few date formats although I couldn't find your exact format and it also supports a lot of different versions for displaying the author name.
推荐阅读
- python - TensorFlow CUDNN_STATUS_EXECUSION_FAILED 错误仅适用于 nvidia Quadro T2000
- javascript - 调用嵌套的 javascript 函数
- python - 具有多列的 Pandas Dataframe Groupby 并将其求和
- node.js - 如何在 Sequelize nodejs 中使用条件语句编写 bulkUpdate。为每个元素更新具有某些条件的元素列表
- ios - 为什么委托模式不适用于 TabBarController 的自定义视图?
- .net - 如何从 URL 的 Web 应用程序中的字体文件中获取字体系列?
- angular-material - 使用 Angular 服务和材料输入构建异步下拉菜单
- c++ - c ++模板元编程:如何为我的自定义特征定义类型特征“is_xxxxx_v”别名?
- c - 这个 ```typedef``` 声明是什么?
- json - 将 Python Dict 转换为 Object 并在 JSON Python3.7 中解码的简单方法