行历史查看器 - 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:50:49  来源:igfitidea点击:

Line history viewer - Git

gitidelineversioning

提问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 blamecommands to iterate over history of a fragment.

您还可以尝试使用多个git blame命令来迭代片段的历史记录。

回答by Lu55

Maybe annotations in IntelliJ IDEAis that you are looking for:

也许您正在寻找IntelliJ IDEA 中的注释

the left gutter with enabled annotations

启用注释的左侧装订线

Showing and hiding annotations

显示和隐藏注释

  1. Open the desired file in the editor.
  2. To show annotations, right-click the left gutter, and select Annotate:
    context menu
  3. To hide annotations, right-click the annotations gutter, and choose Close Annotations.
  1. 在编辑器中打开所需的文件。
  2. 要显示注释,请右键单击左侧装订线,然后选择Annotate
    上下文菜单
  3. 要隐藏注释,请右键单击注释装订线,然后选择关闭注释

回答by naXa

git blame (docs)

git 责备(文档)

git-blameshows 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

git log (docs)

git log (文档)

git-logshows commit logs.

git-log显示提交日志。

Usage example

使用示例

You can specify -L option to trace the evolution of the line range given by ",". You can specify this option more than once.

您可以指定 -L 选项来跟踪由“,”给出的行范围的演变。您可以多次指定此选项。

git log -L 40,50:foo.txt

回答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.

找到下面的屏幕截图,其中显示了此选项及其在社区版中也可用。

enter image description here

在此处输入图片说明

回答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.

更多信息:每一行代码总是被记录在案。