簡體   English   中英

如何使用git列出目錄的每個文件的原始提交(時間和作者)?

[英]How to list the original commits (time and author) per file of a directory with git?

我想用 git 列出我(以ls風格):

  • 誰是該文件的原作者
  • 創建文件時

我正在尋找這樣的輸出:

File           Original Author         First Added       Commit
----------------------------------------------------------------
a.yaml            tom                  01/01/2020        1a12121
b.yaml            felix                05/01/2020        ad12257
[...]

他用 git 有什么可能嗎?

您可以使用git log --pretty-format--diff-filter=AA表示添加):

#!/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

例子:

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支持幾種日期格式,雖然我找不到你的確切格式,它也支持許多不同的版本來顯示作者姓名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM