Git.Gogs规范和Build构建

image.png

check cloudwisdom code analysis lines

cw-hms-web project

set +x
echo "starting analysis now ..............."
echo "staring cw-hms-web codeline analysis ................"
cd /var/lib/jenkins/workspace/cw-hms-web
git branch
git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/';

git log --oneline | wc -l;

echo "------------------------------------------------------------------------"
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t";

git log --author="$name" --until=2.weeks.ago --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

git log --author="$name" --since=1.month.ago --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

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

git log --author="$(git config --get user.name)" --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -

--since=`.month.ago --until=2.weeks.ago

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

echo "###############################################################################"

cw-pos-web project

echo "staring cw-pos-web codeline analysis ................"
cd /var/lib/jenkins/workspace/cw-pos-web
git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/';

git log --oneline | wc -l;

echo "------------------------------------------------------------------------"
git branch
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t";

git log --author="$name" --until=2.weeks.ago --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

git log --author="$name" --since=1.month.ago --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

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

cw-hms-source project

echo "###############################################################################"
echo "staring cw-hms-source codeline analysis ................"
cd /var/lib/jenkins/workspace/cw-hms-source
git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/';

git log --oneline | wc -l;

echo "------------------------------------------------------------------------"
git branch
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t";

git log --author="$name" --until=2.weeks.ago --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

git log --author="$name" --since=1.month.ago --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

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

--since=`.month.ago --until=2.weeks.ago

cw-winservice project

echo "###############################################################################"

mkdir: XX (创建一个空目录 XX指目录名)
pwd: 显示当前目录的路径。
git init 把当前的目录变成可以管理的git仓库,生成隐藏.git文件。
git add XX 把xx文件添加到暂存区去。
git commit –m “XX” 提交文件 –m 后面的是注释。
git status 查看仓库状态
git diff XX 查看XX文件修改了那些内容
git log 查看历史记录
git reset –hard HEAD^ 或者 git reset –hard HEAD~ 回退到上一个版本
(如果想回退到100个版本,使用git reset –hard HEAD~100 )
cat XX 查看XX文件内容
git reflog 查看历史记录的版本号id
git checkout — XX 把XX文件在工作区的修改全部撤销。
git rm XX 删除XX文件
git remote add origin https://github.com/tugenhua0707/testgit 关联一个远程库
git push –u(第一次要用-u 以后不需要) origin master 把当前master分支推送到远程库
git clone https://github.com/tugenhua0707/testgit 从远程库中克隆
git checkout –b dev 创建dev分支 并切换到dev分支上
git branch 查看当前所有的分支
git checkout master 切换回master分支
git merge dev 在当前的分支上合并dev分支
git branch –d dev 删除dev分支
git branch name 创建分支
git stash 把当前的工作隐藏起来 等以后恢复现场后继续工作
git stash list 查看所有被隐藏的文件列表
git stash apply 恢复被隐藏的文件,但是内容不删除
git stash drop 删除文件
git stash pop 恢复文件的同时 也删除文件
git remote 查看远程库的信息
git remote –v 查看远程库的详细信息
git push origin master Git会把master分支推送到远程库对应的远程分支上
Git 非常复杂。我即使几乎每天都在用,也不敢保证对 Git 的每一个角落都了如指掌。
本文试图盘点一些不知名,但在我看来较常用的操作。如果没有你预期的操作,说明要么在我看来它很知名,要么在我看来它不太常用。

git log --graph --abbrev-commit --decorate --all --oneline
git cherry
git show ref:path
git reset [--hard|--soft|--keep]
git update-index --assume-unchanged
git log --graph --abbrev-commit --decorate --all --oneline
#############################################################
Git.Gogs规范和Build构建
查看git上个人代码量

check cloudwisdom code analysis lines

cw-hms-web project

set +x
echo "starting analysis now ..............."
cd /var/lib/jenkins/workspace/cw-hms-web
git branch
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t";
git log --author="$name" --until=2.weeks.ago --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

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

git log --author="$(git config --get user.name)" --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -

--since=`.month.ago --until=2.weeks.ago

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

echo "###############################################################################"

cw-pos-web project

cd /var/lib/jenkins/workspace/cw-pos-web
git branch
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t";
git log --author="$name" --until=2.weeks.ago --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

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

cw-hms-source project

echo "###############################################################################"
cd /var/lib/jenkins/workspace/cw-hms-source
git branch
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t";
git log --author="$name" --until=2.weeks.ago --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

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

cw-winservice project

echo "###############################################################################"
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 }' -
统计每个人的增删行数

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

git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5
贡献者统计:

git log --pretty='%aN' | sort -u | wc -l
提交数统计:

git log --oneline | wc -l

添加或修改的代码行数:

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

统计某人的代码提交量,包括增加,删除:
git log --author="$(git config --get user.name)" --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -
仓库提交者排名前 5(如果看全部,去掉 head 管道即可):
git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5
仓库提交者(邮箱)排名前 5:这个统计可能不会太准,因为很多人有不同的邮箱,但会使用相同的名字
git log --pretty=format:%ae | gawk -- '{ ++c[$0]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }' | sort -u -n -r | head -n 5
贡献者统计:
git log --pretty='%aN' | sort -u | wc -l
提交数统计:
git log --oneline | wc -l
添加或修改的代码行数:
git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;

git log 参数说明:
--author 指定作者
--stat 显示每次更新的文件修改统计信息,会列出具体文件列表
--shortstat 统计每个commit 的文件修改行数,包括增加,删除,但不列出文件列表:
--numstat 统计每个commit 的文件修改行数,包括增加,删除,并列出文件列表:

-p 选项展开显示每次提交的内容差异,用 -2 则仅显示最近的两次更新
例如:git log -p -2
--name-only 仅在提交信息后显示已修改的文件清单
--name-status 显示新增、修改、删除的文件清单
--abbrev-commit 仅显示 SHA-1 的前几个字符,而非所有的 40 个字符
--relative-date 使用较短的相对时间显示(比如,“2 weeks ago”)
--graph 显示 ASCII 图形表示的分支合并历史
--pretty 使用其他格式显示历史提交信息。可用的选项包括 oneline,short,full,fuller 和 format(后跟指定格式)
例如: git log --pretty=oneline ; git log --pretty=short ; git log --pretty=full ; git log --pretty=fuller
--pretty=tformat: 可以定制要显示的记录格式,这样的输出便于后期编程提取分析
例如:git log --pretty=format:""%h - %an, %ar : %s""
下面列出了常用的格式占位符写法及其代表的意义。
选项 说明
%H 提交对象(commit)的完整哈希字串
%h 提交对象的简短哈希字串
%T 树对象(tree)的完整哈希字串
%t 树对象的简短哈希字串
%P 父对象(parent)的完整哈希字串
%p 父对象的简短哈希字串
%an 作者(author)的名字
%ae 作者的电子邮件地址
%ad 作者修订日期(可以用 -date= 选项定制格式)
%ar 作者修订日期,按多久以前的方式显示
%cn 提交者(committer)的名字
%ce 提交者的电子邮件地址
%cd 提交日期
%cr 提交日期,按多久以前的方式显示
%s 提交说明
--since 限制显示输出的范围,
例如: git log --since=2.weeks 显示最近两周的提交
选项 说明
-(n) 仅显示最近的 n 条提交
--since, --after 仅显示指定时间之后的提交。
--until, --before 仅显示指定时间之前的提交。
--author 仅显示指定作者相关的提交。
--committer 仅显示指定提交者相关的提交。

一些例子: git log --until=1.minute.ago // 一分钟之前的所有 log git log --since=1.day.ago //一天之内的log git log --since=1.hour.ago //一个小时之内的 log git log --since=`.month.ago --until=2.weeks.ago //一个月之前到半个月之前的log git

log --since ==2013-08.01 --until=2013-09-07 //某个时间段的 log git blame
看看某一个文件的相关历史记录
例如:git blame index.html --date short

你可能感兴趣的:(Git.Gogs规范和Build构建)