致命错误:提交标识

时间:2016-04-02 06:19:46

标签: git

我试图运行.sh文件,该文件将为应用程序的所有文件提取每次提交的作者详细信息。它适用于示例文件,但是当我尝试为少数文件组合和提交ID运行相同的shell脚本时,我发现致命错误,说路径在特定的提交ID中不存在。但实际上,该文件存在相同的提交ID。

请解释问题的可能原因并提出一些解决方案,以便我能够克服这个问题。以下是我正在使用的代码

#!/bin/bash
# get the list of files present in the current directory
files=`git ls-files "*.java"`
# removing whitespace
fn=( $files )
# using for loop to iterate through each file
for ((j=0; j <${#fn[@]}; j++))
do
    # To get the file name - as the fn returns the sub-directory path
    filename=$(basename ${fn[$j]})
# split the Set of SHA values 
IFS=';' 
arr=($SHA)
# To iterate through each commit of the file
    for ((i=0; i <${#arr[@]}; i++))
    do
    echo *fileName*
    echo $filename
    echo *EndfileName*
    # To remove new line from the SHA id 
    commitId1=$(echo ${arr[$i]}|tr -d '\n')
    owner=`git blame --line-porcelain ${fn[$j]} $commitId1 | grep "^author " | sort | uniq -c`
    done
done

我是shell脚本和git的新手。如果代码不好,请原谅我

1 个答案:

答案 0 :(得分:0)

要获得所有作者,只需执行

即可
git log --format='%aN'

以下内容还将打印commit hash

git log --format='%aN %H'

git log支持更多格式:请参阅here