轩_雨

青山不厌三杯酒,长日惟消一局棋
git——git不常见指令记录
  1. 查看本次pull和上一次本地commit的文件变更情况
    git diff --name-only `git reflog -n 2 | tail -n 1 | awk '{printf $1}'` `git reflog -n 1 | awk '{printf $1}'` 
    
  2. 查看不同用户贡献的代码行数
    git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done
    
  3. 统计代码行数
    cloc Build Status
    cloc --vcs=git . | grep SUM | awk '{file=$2;blank=$3;comment=$4;code=$5;lines=$3+$4+$5} END {printf "files: %s, blank lines: %s, comment lines: %s, code lines: %s, total lines: %s\n", file, blank, comment, code, lines}'
    
  4. 在裸库里统计代码行数
    这会比2更快,但是只有代码行,不能统计注释
    git diff `git rev-parse HEAD`  `git log --reverse | head -n 1 | awk '{print $2}'` --pretty=tformat: --numstat | awk '{total+=$2-$1} END {printf "%s", total}'
    git log `git log --reverse | head -n 1 | awk '{print $2}'` --pretty=tformat: --numstat | awk '{total+=$1-$2} END {printf "%s", total}'
    

posted on 2021-12-05 16:56  轩_雨  阅读(31)  评论(0编辑  收藏  举报