Git:谁修改了这一行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6143872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: Who has modified this line?
提问by Ivan
If I found a bug in my application, sometimes I need to know which commits have affected to the bug source code line. I'm wondering which is the best approach to do it with Git.
如果我在我的应用程序中发现了一个错误,有时我需要知道哪些提交影响了错误源代码行。我想知道用 Git 做这件事的最佳方法是什么。
采纳答案by vcsjones
回答by ahaurat
To see commits affecting line 40 of file foo:
要查看影响文件 foo 的第 40 行的提交:
git blame -L 40,+1 foo
The +1 means exactly one line. To see changes for lines 40-60, it's:
+1 表示正好一行。要查看第 40-60 行的更改,它是:
git blame -L 40,+21 foo
OR
或者
git blame -L 40,60 foo
The second number can be an offset designated with a '+', or a line number. git blame docs
第二个数字可以是用“+”或行号指定的偏移量。git 责备文档
回答by Seth Robertson
git blame filename
is the best command to show you this info
是向您显示此信息的最佳命令
回答by Frank Schmitt
If you only need the last change:
如果您只需要最后一次更改:
git blame
Otherwise, you could try to automatically find the offending change with
否则,您可以尝试自动找到有问题的更改
git bisect
回答by Nayagam
You can use
您可以使用
git annotate filename (or)
git blame filename