有没有办法让 git diff 显示方法名称而不是类名称?
这已经困扰我一段时间了,搜索也没有得到任何提示。
问题:
当我对包含 Class
的 PHP 文件执行 git diff
时,每个块描述都有类名,但没有提及方法姓名。
例如:
@@ -351,7 +351,7 @@ class Session
$form->setError($field, $subpassValid['msg']);
}
// E-Mail address error checking
$field = "email"; //Use field name for email
- if(!isset($subemail) || strlen($subemail = trim($subemail)) == 0){
+ if(!$subemail || strlen($subemail = trim($subemail)) == 0){
$form->setError($field, "* Email not entered");
@@ -373,7 +373,7 @@ class Session
...
问题:
有没有办法告诉 git
显示方法名称而不是/沿着类名称?
编辑:
其他信息:
diff version: 2.8.1
git version: 1.7.6 (from the git-core PPA)
OS: Ubuntu 9.10
我最初从 Ubuntu 存储库中获得了 git 版本 1.7.0.4,但更新了它,希望这是一个错误。不幸的是,这并没有解决问题。
Edit2:
经过更多测试,看来函数声明是否缩进(使用空格或制表符)git diff
不获取函数名称。这似乎是 git
中的一个错误。
This has been bugging me for a while and searching has yielded no hints.
Issue:
When I do a git diff
on a PHP file containing a Class
, each hunk description has the class name with no mention of the method name.
For example:
@@ -351,7 +351,7 @@ class Session
$form->setError($field, $subpassValid['msg']);
}
// E-Mail address error checking
$field = "email"; //Use field name for email
- if(!isset($subemail) || strlen($subemail = trim($subemail)) == 0){
+ if(!$subemail || strlen($subemail = trim($subemail)) == 0){
$form->setError($field, "* Email not entered");
@@ -373,7 +373,7 @@ class Session
...
Question:
Is there a way to tell git
to show method names instead of/along side of the class name?
Edit:
Additional Information:
diff version: 2.8.1
git version: 1.7.6 (from the git-core PPA)
OS: Ubuntu 9.10
I originally had git version 1.7.0.4 from the stock Ubuntu repos, but updated it hoping that it was a bug. Unfortunately that didn't solve the issue.
Edit2:
After more testing, it appears that if the function declaration is indented at all (with either spaces or tabs) git diff
doesn't pick up the function name. This appears to be a bug in git
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您发现自己遇到此问题,可能是由于
git
让diff
定义 hunk 标头。如果您想强制git
使用 PHP 的预定义属性,请将以下行放在 git 存储库根文件夹中的.gitattributes
或.git 中存储库中的 /info/attributes
文件:(类似地支持其他语言。内置模式的列表可在 文档。)
全局设置
应该可以通过在
中执行以下操作来全局设置它>git version >= 1.4
~/.gitattributes
git config --global core.attributesfile "~/.gitattributes"
或者,如果您想全局设置此值
/etc/gitattributes
警告: 如果您个人全局设置此值,您的同事在运行 git diff 时可能会得到不同的结果,因为他们不会使用存储库检出 .gitattributes 的副本。
If you find yourself having this issue, it might be due to the fact that
git
letsdiff
define the hunk header. If you want to forcegit
to use its predefined ones for PHP place the following line in either.gitattributes
in the root folder of your git repository or the.git/info/attributes
file in your repository:(Other languages are similarly supported. A list of the built in patterns is available in the documentation.)
Setting this Globally
It should be possible to globally set this by doing the following in
git version >= 1.4
~/.gitattributes
git config --global core.attributesfile "~/.gitattributes"
Or if you want to set this globally
/etc/gitattributes
Warning: If you personally set this globally, your peers may get different results when running
git diff
since they won't checkout a copy of.gitattributes
with the repository.我不太明白为什么它不能按应有的方式工作。
作为临时解决方案,请将以下内容添加到
.gitattributes
:并将这些行添加到
.git/config
或~/.gitconfig
:对于永久解决方案解决方案直接询问 Git 开发人员 [电子邮件受保护]邮件列表。
I don't quite understand why it doesn't work the way it should.
As a temporary solution, add the following to
.gitattributes
:And these lines to
.git/config
or~/.gitconfig
:For a permanent solution ask Git developers directly at [email protected] mailing list.
使用 Git 2.19(2018 年第 3 季度)该 diff 可能会更好,因为
.php
的 userdiff 模式已更新。请参阅 提交 1ab6316,提交 9992fbd(2018 年 7 月 3 日),作者:假名夏野(
假名
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 d3f0938,2018 年 7 月 24 日)Git 2.30(2021 年第一季度)确实有所改进:
请参阅 commit aff9282(10 月 7 日 ) 2020)由 Javier Spagnoletti (
phansys
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 a8a49eb,2020 年 10 月 27 日)That diff would likely be better with Git 2.19 (Q3 2018), since the userdiff pattern for
.php
has been updated.See commit 1ab6316, commit 9992fbd (03 Jul 2018) by Kana Natsuno (
kana
).(Merged by Junio C Hamano --
gitster
-- in commit d3f0938, 24 Jul 2018)And it does improve with Git 2.30 (Q1 2021):
See commit aff9282 (07 Oct 2020) by Javier Spagnoletti (
phansys
).(Merged by Junio C Hamano --
gitster
-- in commit a8a49eb, 27 Oct 2020)