blame git
With git blame
you can see who changed what in a specific file, line by line, which is useful if you work in a team, instead of alone. For example, if a line of code makes you wonder why it is there, you can use git blame
and you will know who you must ask.
使用git blame
您可以看到谁逐行更改了特定文件中的内容,这对于团队合作而不是一个人工作很有用。 例如,如果一行代码使您想知道为什么会有代码,则可以使用git blame
,您将知道必须询问谁。
用法 (Usage)
You use git blame
like this: git blame NAME_OF_THE_FILE
您可以这样使用git blame
: git blame NAME_OF_THE_FILE
For example: git blame triple_welcome.rb
例如: git blame triple_welcome.rb
You will see an output like this:
您将看到类似以下的输出:
0292b580 (Jane Doe 2018-06-18 00:17:23 -0500 1) 3.times do
e483daf0 (John Doe 2018-06-18 23:50:40 -0500 2) print 'Welcome '
0292b580 (Jane Doe 2018-06-18 00:17:23 -0500 3) end
Each line is annotated with the SHA, name of the author and date of the last commit.
每行都用SHA,作者姓名和最后提交日期注释。
别名Git责备 (Aliasing Git Blame)
Some programmers don’t like the word ‘blame’, because of the negative connotation ‘blaming someone’ brings with it. Also, the tool is rarely (if ever) used for blaming someone, but rather to ask for advice or understand the history of a file. Therefore, sometimes people use an alias to change git blame
to something which sounds a bit nicer such as git who
, git history
or git praise
. To do that you simply add a git alias like this:
一些程序员不喜欢“责备”一词,因为它带有负面含义“责备某人”。 而且,该工具很少(如果有的话)用来指责某人,而是寻求建议或了解文件的历史记录。 因此,有时人们使用别名将git blame
更改为听起来更好的东西,例如git who
, git history
或git praise
。 为此,您只需添加一个git别名,如下所示:
git config --global alias.history blame
git config --global alias.history blame
You can find more information about aliasing git commands here.
您可以在此处找到有关别名git命令的更多信息。
利用Git Blame的文本编辑器插件 (Text Editor Plugins utilizing Git Blame)
There are a few plugins out there for various text editors which utilize git blame
. For example, to create something like heat maps or add inline information for the current line you are inspecting. A famous example is GitLense for VSCode.
有一些插件git blame
各种文本编辑器使用。 例如,要创建诸如热图之类的东西或为您要检查的当前管线添加内联信息。 一个著名的例子是VSCode的GitLense。
翻译自: https://www.freecodecamp.org/news/git-blame-explained-with-examples/
blame git