行历史查看器 - Git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15661110/
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
Line history viewer - Git
提问by David.LPower
I was wondering if any of you knew of a tool that would allow me to select a line in my code and then view a list view of the history of that line, on a commit by commit basis.
我想知道你们中是否有人知道一种工具,它可以让我在我的代码中选择一行,然后在逐个提交的基础上查看该行历史的列表视图。
Anyone know of such a tool?
有人知道这样的工具吗?
采纳答案by kan
I know only the IntelliJ IDEA "Viewing Changes History for Selection" feature.
我只知道 IntelliJ IDEA 的“查看更改历史记录以供选择”功能。
You could also try to use several git blame
commands to iterate over history of a fragment.
您还可以尝试使用多个git blame
命令来迭代片段的历史记录。
回答by Lu55
Maybe annotations in IntelliJ IDEAis that you are looking for:
也许您正在寻找IntelliJ IDEA 中的注释:
Showing and hiding annotations
显示和隐藏注释
回答by naXa
git blame (docs)
git 责备(文档)
git-blame
shows what revision and author last modified each line of a file.
git-blame
显示文件的每一行最后修改的版本和作者。
Usage examples
使用示例
When you are interested in finding the origin for lines 40-50 for file foo, you can use the -L option like so (they mean the same thing?—?both ask for 11 lines starting at line 40):
当您有兴趣为文件 foo 找到第 40-50 行的原点时,您可以像这样使用 -L 选项(它们的意思相同?-?都要求从第 40 行开始的 11 行):
git blame -L 40,50 foo.txt
git blame -L 40,+11 foo.txt
You can specify a revision for git blame to look back starting from (instead of the default of HEAD) if you want to find out who edited that lines before a specific commit (fe25b6d in this example; fe25b6d^ is the parent of fe25b6d):
如果您想找出在特定提交之前谁编辑了该行(在此示例中为 fe25b6d;fe25b6d^ 是 fe25b6d 的父级),您可以为 git blame 指定一个修订以从(而不是默认的 HEAD)开始回顾:
git blame -L 40,+11 fe25b6d^ -- foo.txt
回答by naXa
回答by Opster Elasticsearch Ninja
If you are using IntelliJ then, its annotation feature provides an option to do the annotation on previous revision. Using this option you can go back to the history of that line.
如果您正在使用 IntelliJ,那么它的注释功能提供了一个选项来对以前的版本进行注释。使用此选项,您可以返回到该行的历史记录。
Find below screen-shot which shows, This option and its available in community edition as well.
找到下面的屏幕截图,其中显示了此选项及其在社区版中也可用。
回答by Snger
As suggested in one of the comments in Can Git show history for selected lines?
正如Can Git show historyof selected lines中的评论之一所建议的那样?
git show $(git blame example.js -L 250,260 | awk '{print }')
more info: Every line of code is always documented.
更多信息:每一行代码总是被记录在案。