2017-10-08 132 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 
相關問題