'git 责备' 有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31203001/
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-09 03:21:42  来源:igfitidea点击:

What does 'git blame' do?

gitgit-blame

提问by Himanshu Mishra

I saw a lot of questions about methods of using git blame, but I don't really understand them.

我看到很多关于使用方法的问题git blame,但我并没有真正理解它们。

I see a Blamebutton on top of files on the GitHub interface. Upon clicking it, it shows some diff with usernames on the left bar. What does that indicate?

Blame在 GitHub 界面上的文件顶部看到一个按钮。单击它后,它会在左侧栏上显示与用户名的一些差异。这说明什么?

Why is git blameactually used, apart from GitHub?

git blame除了GitHub之外,为什么实际使用?

采纳答案by Mark

From git-blame:

来自git-blame

Annotates each line in the given file with information from the revision which last modified the line. Optionally, start annotating from the given revision.

When specified one or more times, -L restricts annotation to the requested lines.

使用上次修改该行的修订版中的信息对给定文件中的每一行进行注释。或者,从给定的修订开始注释。

当指定一次或多次时,-L 将注释限制为请求的行。

Example:

例子:

[email protected]:~# git blame .htaccess
...
^e1fb2d7 (John Doe 2015-07-03 06:30:25 -0300  4) allow from all
^72fgsdl (Arthur King 2015-07-03 06:34:12 -0300  5)
^e1fb2d7 (John Doe 2015-07-03 06:30:25 -0300  6) <IfModule mod_rewrite.c>
^72fgsdl (Arthur King 2015-07-03 06:34:12 -0300  7)     RewriteEngine On
...

Please note that git blamedoes not show the per-line modifications history in the chronological sense. It only shows who was the last person to have changed a line in a document up to the last commit in HEAD.

请注意,git blame它不会按时间顺序显示每行的修改历史。它只显示谁是最后一个更改文档中一行的人,直到HEAD.

That is to say that in order to see the full history/log of a document line, you would need to run a git blame path/to/filefor each commit in your git log.

也就是说,为了看到完整的历史/日志文件行,你需要运行git blame path/to/file在您的每一次提交git log

回答by XRay

The command explains itself quite well. It's to figure out which co-worker wrote the specific line or ruined the project, so you can blamethem :)

该命令很好地解释了自身。就是找出哪个同事写了具体的行或破坏了项目,所以你可以责怪他们:)

回答by Himanshu Mishra

From GitHub:

来自 GitHub

The blame command is a Git feature, designed to help you determine who made changes to a file.

Despite its negative-sounding name, git blame is actually pretty innocuous; its primary function is to point out who changed which lines in a file, and why. It can be a useful tool to identify changes in your code.

blame 命令是 Git 的一项功能,旨在帮助您确定谁对文件进行了更改。

尽管它的名字听起来很消极,但 git blame 实际上是无害的。它的主要功能是指出谁更改了文件中的哪些行,以及为什么更改。它可以成为识别代码更改的有用工具。

Basically, git-blameis used to show what revision and author last modified each line of a file. It's like checking the history of the development of a file.

基本上,git-blame用于显示文件的每一行最后修改的版本和作者。这就像检查文件的开发历史。

回答by Bharath T S

The git blamecommand is used to know who/which commit is responsible for the latest changes made to a file. The author/commit of each line can also been seen.

git blame命令用于了解谁/哪个提交负责对文件所做的最新更改。还可以看到每一行的作者/提交。

git blame filename(commits responsible for changes for all lines in code)

git blame filename(提交负责代码中所有行的更改)

git blame filename -L 0,10(commits responsible for changes from line "0" to line "10")

git blame filename -L 0,10(提交负责从“0”行到“10”行的变化)

There are many other options for blame, but generally these could help.

还有许多其他的指责选择,但通常这些可能会有所帮助。

回答by VonC

The git blamecommand annotates lines with information from the revision which last modified the line, and... with Git 2.22 (Q2 2019), will do so faster, because of a performance fix around "git blame", especially in a linear history (which is the norm we should optimize for).

git blame命令使用上次修改该行的修订版中的信息对行进行注释,并且...使用 Git 2.22(2019 年第二季度)会更快,因为围绕“ git blame”的性能修复,尤其是在线性历史记录中(这是我们应该优化的规范)。

See commit f892014(02 Apr 2019) by David Kastrup (fedelibre). (Merged by Junio C Hamano -- gitster--in commit 4d8c4da, 25 Apr 2019)

请参阅David Kastrup ( )提交的 f892014(2019 年 4 月 2 日(由Junio C Hamano合并-- --commit 4d8c4da,2019 年 4 月 25 日)fedelibregitster

blame.c: don't drop origin blobs as eagerly

When a parent blob already has chunks queued up for blaming, dropping the blob at the end of one blame step will cause it to get reloaded right away, doubling the amount of I/O and unpacking when processing a linear history.

Keeping such parent blobs in memory seems like a reasonable optimization that should incur additional memory pressure mostly when processing the merges from old branches.

blame.c: 不要急切地丢弃原始 blob

当父 blob 已经有块排队等待指责时,在一个指责步骤结束时丢弃 blob 将导致它立即重新加载,使 I/O 量加倍,并在处理线性历史时解包。

将这样的父 blob 保留在内存中似乎是一种合理的优化,主要是在处理来自旧分支的合并时会产生额外的内存压力。

回答by Hymanzhoumine

The git blamecommand is used to examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was.

git blame命令用于逐行检查文件的内容,并查看每行最后一次修改的时间以及修改的作者是谁。

If there was a bug in code,use it to identify who cased it,then you can blame him. Git blame is get blame.

如果代码中存在错误,用它来确定是谁造成的,然后你可以责怪他。Git 责备是得到责备。

If you need to know history of one line code,use git log -S"code here", simpler than git blame.

如果您需要了解一行代码的历史,请使用git log -S"code here",比 git blame 更简单。

git log vs git blame

git 日志 vs git 责备