2017-10-08 129 views
0

因此,我与一些其他程序员一起在一个团队中,需要在我们的git存储库中为每个作者获取一行代码数。这不仅仅意味着作者修改过的行,因为这将包括空行和注释行。理想情况下,我可以创建一个仅包含特定作者提交的新分支(我自己的--author="BtheDestroyer"),然后使用cloc分别获取注释行数和代码行数。我的最后行期间使用在git存储库中为每个作者计算代码行数

git log --author="BtheDestroyer" --format=%H > mycommits 
git checkout --orphan mycommits 
tac mycommits| while read sha; do git cherry-pick --no-commit ${sha}; done 

试过了,但是,我得到一吨以下错误:

filepath: unmerged (commit-id-1) 
filepath: unmerged (commit-id-2) 
error: your index file is unmerged. 
fatal: cherry-pick failed 

我也不能肯定是否会最终通过其他提交快进正在进行中。有任何想法吗?

回答

0

回答我的问题:

我结束了使用git blame,并通过在源文件夹不同的文件Bourne shell脚本循环,将它们转换回到使用grepcut代码,输出组织成临时文件,然后运行cloc

这是我想要的任何人做同样的事情(我有它在./Blame/所以更改SOURCE适当!)shell脚本:

#!/bin/bash 
#Name of user to check 
# If you have multiple usernames, separate them with a space 
# The full name is not required, just enough to not be ambiguous 
USERS="YOUR USERNAMES HERE" 
#Directories 
SOURCE=../source 

for USER in $USERS 
do 
    #clear blame files 
    echo "" > $USER-Blame.h 
    echo "" > $USER-Blame.cpp 
    echo "" > $USER-Blame.sh 
    echo "Finding blame for $USER..." 
    #C++ files 
    echo " Finding blame for C++ files..." 
    for f in $SOURCE/*.cpp 
    do 
     git blame "$f" | grep "$USER" | cut -c 70- >> "$USER-Blame.cpp" 
    done 
    #Header files 
    echo " Finding blame for Header files..." 
    for f in $SOURCE/*.h 
    do 
     git blame "$f" | grep "$USER" | cut -c 70- >> "$USER-Blame.h" 
    done 
    #Shell script files 
    echo " Finding blame for shell script files..." 
    for f in ./GetUSERBlame.sh 
    do 
     git blame "$f" | grep "$USER" | cut -c 70- >> "$USER-Blame.sh" 
    done 
done 

for USER in $USERS 
do 
#cloc 
echo "Blame for all users found! Cloc-ing $USER..." 
cloc $USER-Blame.* --quiet 
#this line is for cleaning up the temporary files 
#if you want to save them for future reference, comment this out. 
rm $USER-Blame.* -f 
done 
相关问题