git 定位代码责任人

git blame 定位代码责任人
git bisect 查找问题引入版本
git grep 查找指定内容的位置
git log 查找指定内容的历史记录

一、git blame 定位代码责任人
1.文件较小:git log -p -- file

2.大文件:
git blame file

这个输出的内容过多,定位到指定的行数(1-3的代码责任人)
git blame -L 1,3 file

从第五行开始,包括第五行,+3是偏移量(从第五行开始往下的三行)
git blame -L 5,+3 file 
git blame -L 5,+3  与 git blame -L 5,7 file 相同 

二、git bisect 查找问题引入版本
git bisect start 表明 bisect的一个过程
git bisect bad 标明当前master分支有问题的一个版本
git bisect good C1 标明C1分支是的一个正常的版本
git bisect bad  通过测试标明C1与当前master版本定位到中间的一个版本C3,是有问题的一个版本,标记有问题的一个版本
git bisect good 如果中间还有C2版本,经过测试是一个好的版要,标记一个好的版本,
这时有问题的一个版本是C3,会把C3有问题的版本改动的文件名告诉你

git bisect reset 表明bitsect 过程已经结束了,git 把Head 指向master分支

eg:
hairongchen:FFMpegPlayer (master)$ git log --oneline
d346d88 ffmpeg3.0 library
d52a24f tools
7babbbe README.md
6d96170 first commit
hairongchen:FFMpegPlayer (master)$ git bisect start
hairongchen:FFMpegPlayer (master|BISECTING)$ git bisect bad
hairongchen:FFMpegPlayer (master|BISECTING)$ git bisect good 6d96170
Bisecting: 0 revisions left to test after this (roughly 1 step)
[d52a24ff0cc22cc096714615f5c95cf1b3db727a] tools
hairongchen:FFMpegPlayer ((d52a24f...)|BISECTING)$ 

直接跳到d52a24f,head指向d52a24f,对d52a24f进行检验之后,确定d52a24f也是有问题的使用:

git bisect bad 就会跳到d52a24f tools 与6d96170 first commit 中间的版本:7babbbe README.md

eg:
hairongchen:FFMpegPlayer ((d52a24f...)|BISECTING)$ git bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[7babbbefb041884e1d8aa582fd8970f1b67d1e19] README.md
hairongchen:FFMpegPlayer ((7babbbe...)|BISECTING)$ 

经过检查,发现7babbbe 是好的,进行标记:
git bisect good
eg:
hairongchen:FFMpegPlayer ((7babbbe...)|BISECTING)$ git bisect good
d52a24ff0cc22cc096714615f5c95cf1b3db727a is the first bad commit
commit d52a24ff0cc22cc096714615f5c95cf1b3db727a
Author: rhc <bawfnhaps@163.com>
Date:   Sun May 29 11:55:18 2016 +0800

    tools

:000000 040000 0000000000000000000000000000000000000000 10d35028e498fc74eb8f0023aeced4f21245fc05 Atools
hairongchen:FFMpegPlayer ((7babbbe...)|BISECTING)$ 

就告诉我们第一个有问题的版本是:d52a24ff0cc22cc096714615f5c95cf1b3db727a,修改了tools
文件内容从000000 变更为10d35028e

git diff 000000 10d35028
git bisect reset 结束二分查找引用,head指向的分支
由于二分查找和标记非常多,有些标记错了,这个时候应该:
git bisect start
git bisect bad
git bisect good  6d96170
那么会跳到:d52a24ff0cc22cc096714615f5c95cf1b3db727a] tools

eg:
hairongchen:FFMpegPlayer (master +)$ git bisect start
hairongchen:FFMpegPlayer (master|BISECTING)$ git bisect bad
hairongchen:FFMpegPlayer (master|BISECTING)$ git bisect good 6d96170
Bisecting: 1 revision left to test after this (roughly 1 step)
[d52a24ff0cc22cc096714615f5c95cf1b3db727a] tools

如果d52a24ff0cc22cc096714615f5c95cf1b3db727a] tools有某些原因不要测试,可使用
git bisect skip
来跳过这个commit,就二支查找到README.md
eg:
hairongchen:FFMpegPlayer ((d52a24f...)|BISECTING)$ git bisect skip
Bisecting: 1 revision left to test after this (roughly 1 step)
[7babbbefb041884e1d8aa582fd8970f1b67d1e19] README.md
hairongchen:FFMpegPlayer ((7babbbe...)|BISECTING)$ 

检查README.md,有问题标记为bad
git bisect bad
又跳到下一个commit
发现这个以前标错了
git bisect good
这时如果跳到前面去了,用git bisect log > bisect.log
log信息输出到文件

vim bisect.log
把标记错误的信息删除,保存
git bisect resect 退出

用git bisect replay bisect.log来重复这么一个过程

继续查:
git bisect good/bad
git bisect resect


三、git grep 查找指定内容的位置
查找含有gmtime_r的内容
git grep gmtimer_r

显示文件名出现的行数:
git grep -n gmtimer_r

使用git grep --count gmtimer_r 在文件中出现的次数

用git grep -p 来显示哪些方法或函数包含gmtimer_r的字符串 并且限定在某
一类文件中
git grep -p gmtime_r *.c


支持下规:
git grep -e 'zhe' //e后为正规表达式
git grep -e 'zhe' --or -e 'ps'//可作意组合
git grep -e 'zhe' --and \( -e 'ps' --or --not -e 'list' \)
git grep -e 'zhe' --and \( -e 'ps' --or --not -e 'list' \) HEAD~ //查找上一个历史版本

四、git log 查找指定内容的历史记录
查看文件中LOG_BUF_MAX 某行什么时候引入的commit:
git log -SLOG_BUF_MAX --oneline

查看什么更改过的信息commit
git log -GLOG_BUF_MAX --oneline

查看被改变的内容:
git log -p -- cc.c

查看某个方法或函数什么时候会引用或删除 还可以查看这一行什么时候被改变过
// git.c file
#define LOG_BUF_MAX 1
unsinged long git_deflate_bounce(z_streamp strm,unsigned long size)
{
return defloateBound(strm,size);
}


git log -L :git_deflate_bounce:git.c
or 
// 以unsinged long git_deflate_bounce开头,以}结尾 后冒号文件名
git log -L :'/unsinged long git_deflate_bounce/',/^}/:git.c 

如果方法名不好写,用下面达到查看文件的历史记录
git log -L 2,5:git.c
git log -L 2,+5:git.c


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值