内容简介:得到的结果,每列分别为
git blame 命令可以查看每行代码的提交详情,包括提交人、时间等信息,成熟的编辑器如 Sublime、Jetbrains 等都集成了这个功能,使用起来非常简单,今天我们来关注下这个命令本身,毕竟在服务器上我们可不能安装这些编辑器。
$ git blame <filename>
得到的结果,每列分别为
提交 sha1 用户名 提交时间 行数 代码 ... 39a22489 (wxnacy 2018-07-26 19:01:55 +0800 6) def filter(source: dict, *args, **kwargs): ...
这是最简单的语法,我们查看文件的每一行代码的最后提交详情,不过这通常不是我们的目的,一般只需要看某一行或某个范围行,这时可以使用 -L 参数。
$ git blame <filename> -L <start>[,<end>]
查看第 10 行
$ git blame <filename> -L 10,10
查看第 10 行及以后
$ git blame <filename> -L 10
查看第 10 到 20 行
$ git blame <filename> -L 10,20
end 也可以加上正负符号,比如
查看 10 行以后 5 行的数据
$ git blame <filename> -L 10,+5
查看 10 行以前 5 行的数据
$ git blame <filename> -L 10,-5
start 和 end 又不止于数字,它还可以是个正则表达式,如果 start 为正则表达式,则会匹配到 end 行,如果 end 为正则表达式,则从 start 行开始匹配,到匹配行截止,如果 start 或者 end 其中之一有值,则从匹配行开始显示全部内容。
查看正则匹配到 20 行
$ git blame <filename> -L /filter/,20
查看 3 行到正则匹配行
$ git blame <filename> -L 3,/filter/
-L 参数的功能还不止这些,有个更智能的方式是直接通过函数名来查看一个区域块的代码
$ git blame <filename> -L:<func_name>
这是很方便的能力,不过只能识别文件最外层的方法名和类名
$ git blame <filename> -L:filter
完整参数列表
usage: git blame [<options>] [<rev-opts>] [<rev>] [--] <file>
<rev-opts> are documented in git-rev-list(1)
--incremental Show blame entries as we find them, incrementally
-b Show blank SHA-1 for boundary commits (Default: off)
--root Do not treat root commits as boundaries (Default: off)
--show-stats Show work cost statistics
--progress Force progress reporting
--score-debug Show output score for blame entries
-f, --show-name Show original filename (Default: auto)
-n, --show-number Show original linenumber (Default: off)
-p, --porcelain Show in a format designed for machine consumption
--line-porcelain Show porcelain format with per-line commit information
-c Use the same output mode as git-annotate (Default: off)
-t 提交时间显示为时间戳,默认关闭
-l 显示完整的 commit sha1,默认关闭
-s Suppress author name and timestamp (Default: off)
-e, --show-email 显示提交用户的邮箱,默认关闭
-w Ignore whitespace differences
--indent-heuristic Use an experimental heuristic to improve diffs
--minimal Spend extra cycles to find better match
-S <file> Use revisions from <file> instead of calling git-rev-list
--contents <file> Use <file>'s contents as the final image
-C[<score>] Find line copies within and across files
-M[<score>] Find line movements within and across files
-L <n,m> Process only line range n,m, counting from 1
--abbrev[=<n>] use <n> digits to display SHA-1s
最近更新
Python 使用 memory_profiler 分析程序内存占用情况
SQLAlchemy 解决其他连接修改数据后,查询不到的问题
Redis get 报错 a key holding the wrong kind of value
最近热读
Go 语法错误:Non-declaration statement outside function body
Python f-strings 3.6 版本新增加的字符串格式化功能
扫码关注公众号,或搜索公众号“温欣爸比” 及时获取我的最新文章
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 查看 Go 的代码优化过程
- 不同工具查看代码分支diff的差异
- Roslyn 入门:使用 Visual Studio 的语法可视化(Syntax Visualizer)窗格查看和了解代码的语法树
- jstack(查看线程)、jmap(查看内存)和jstat(性能分析)命令
- Linux 查看网络流量
- 极简实现列表查看页面
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
程序员面试金典(第5版)
[美] Gayle Laakmann McDowell / 李琳骁、漆 犇 / 人民邮电出版社 / 2013-11 / 59.00
本书是原谷歌资深面试官的经验之作,层层紧扣程序员面试的每一个环节,全面而详尽地介绍了程序员应当如何应对面试,才能在面试中脱颖而出。第1~7 章主要涉及面试流程解析、面试官的幕后决策及可能提出的问题、面试前的准备工作、对面试结果的处理等内容;第8~9 章从数据结构、概念与算法、知识类问题和附加面试题4 个方面,为读者呈现了出自微软、苹果、谷歌等多家知名公司的150 道编程面试题,并针对每一道面试题目......一起来看看 《程序员面试金典(第5版)》 这本书的介绍吧!