Git常用命令备忘 
2017-07-19Git点击王峰 共378字,阅读约需2分钟
克隆远程制定分支到本地
| 1
 | git clone -b <branch> <remote_repo> 
 | 
强制覆盖本地文件
| 12
 3
 
 | git fetch --allgit reset --hard origin/master
 git pull
 
 | 
提交文件
| 12
 3
 
 | git add a.file b.flegit commit -m "备注"
 git push
 
 | 
标签相关
切换到指定分支
检出指定分支
| 1
 | git checkout tags/<tag_name> -b <branch_name>
 | 
新建标签
查看所有标签
统计相关
查看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 }'
 | 
参考
- git统计项目中各成员代码量
- 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/
如果觉得我的文章对您有帮助,请随意打赏。
微信打赏

支付宝打赏
 版权声明:本文由 王峰 发表于 王峰的博客转载声明:自由转载-非商用-非衍生-保持署名,非商业转载请注明作者及出处,商业转载请联系作者本人。文章标题:Git常用命令备忘文章链接: