克隆远程制定分支到本地

1
git clone -b <branch> <remote_repo> ## branch为分支名,remote_repo为远程仓库

强制覆盖本地文件

1
2
3
git fetch --all
git reset --hard origin/master
git pull

提交文件

1
2
3
git add a.file b.fle
git commit -m "备注"
git push

标签相关

切换到指定分支

1
git checkout <branch>

检出指定分支

1
git checkout tags/<tag_name> -b <branch_name>

新建标签

1
git tag <tagName>

查看所有标签

1
git tag

统计相关

查看git上个人代码量

1
git log --author="<username>" --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 }' -

统计每个人的增删行数

1
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

查看仓库提交者排名前 5

1
git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5

贡献者统计

1
git log --pretty='%aN' | sort -u | wc -l

提交数统计

1
git log --oneline | wc -l

统计项目某个某个时间段的行数

1
git log --author="$(git config --get user.name)"  --before='2018-12-31 23:59:59' --after='2018-01-01 00:00:00' --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 }'

参考

  1. git统计项目中各成员代码量
  2. https://liuyueyi.github.io/hexblog/2019/01/27/190127-Git%E9%A1%B9%E7%9B%AE%E4%BB%A3%E7%A0%81%E8%A1%8C%E6%95%B0%E7%BB%9F%E8%AE%A1/