本文介绍了git-diff如何生成大块描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! (git version 1.6.5.7) 当我运行 git diff 时,输出有一个很好的范围提示在我的Python脚本的行号之后,例如: diff --git a / file.py b / file.py index 024f5bb..c3b5c56 100644 --- a / file.py +++ b / file.py @@ -14,6 +14,8 @@ TITF :测试基础架构标签格式 ... @@ -1507,13 +1533,16 @@ class标签(对象): ... TITF:测试基础架构标记格式和 c $ c> class标签(对象):。第一个补丁适用于模块范围,描述 TITF:测试基础架构标签格式是模块的描述。第二个补丁适用于标记类的方法。 git生成这些描述? 如何调整它们以显示补丁适用的方法名称? 解决方案 Git使用正则表达式为大块头找到合适的行。 Python是内置的,但是你应该能够在你的〜/ .gitconfig中定义你自己的表达式: $ b [diff' python] xfuncname =< regex go here> 更多关于此处。 编辑:建-in python正则表达式似乎在 userdiff.c (第53行),尽管我的正则表达式不足以真正理解它到底做了什么...... [a-zA-Z _] [a-zA-Z0-9 _] *| [ - + 0-9.e] + [jJlL]?| 0 [xX]?[ 0-9a-fA-F] + [1L]→| [ - + * / & ^ | =!] = | // =?| | [^ [:space:] | [\x80-\xff] +), / * - * / (git version 1.6.5.7)When I run git diff the output has a nice scope hint after the line numbers for my Python scripts, e.g.:diff --git a/file.py b/file.pyindex 024f5bb..c3b5c56 100644--- a/file.py+++ b/file.py@@ -14,6 +14,8 @@ TITF: Test Infrastructure Tags Format...@@ -1507,13 +1533,16 @@ class Tags( object ):...Note that the line numbers are followed by TITF: Test Infrastructure Tags Format and class Tags( object ):. The first patch applies to module scope and the description TITF: Test Infrastructure Tags Format is the module's description. The second patch applies to a method of the Tags class.How does git generate these descriptions?How can I tweak them to show the method name that the patch applies to? 解决方案 Git uses a regular expression to find a suitable line for the hunk headers. Python's is built-in, but you should be able to define your own expression in your ~/.gitconfig:[diff "python"] xfuncname = "<regex goes here>"More about this here.Edit: The built-in python regex seems to be defined in userdiff.c (line 53), although my regex-fu is not good enough to actually understand exactly what it does...PATTERNS("python", "^[ \t]*((class|def)[ \t].*)$", /* -- */ "[a-zA-Z_][a-zA-Z0-9_]*" "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?" "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?" "|[^[:space:]|[\x80-\xff]+"), /* -- */ 这篇关于git-diff如何生成大块描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 16:29