← 返回命令列表

Linux command

git-blame 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Blame a file

git blame [file.txt]

Blame specific lines

git blame -L [10,20] [file.txt]

Show email addresses

git blame -e [file.txt]

Ignore whitespace

git blame -w [file.txt]

Detect moved lines

git blame -M [file.txt]

说明

git blame shows what revision and author last modified each line of a file. It annotates each line with commit information, helping identify when and why changes were made. The command is essential for code archaeology, understanding code history, and finding who to ask about specific code. Options like -M and -C detect moved and copied code across files to show original authorship rather than the person who relocated it. Line ranges can be specified with -L to focus on specific sections, and -w ignores whitespace changes to find meaningful modifications. The output is invaluable for debugging, code review, and understanding the evolution of specific code sections.

参数

-L _START_,_END_
Annotate specific line range.
-e, --show-email
Show author email.
-w
Ignore whitespace changes.
-M
Detect moved lines within file.
-C
Detect lines copied from other files.
--since _DATE_
Show only commits since date.
--help
Display help information.

FAQ

What is the git-blame command used for?

git blame shows what revision and author last modified each line of a file. It annotates each line with commit information, helping identify when and why changes were made. The command is essential for code archaeology, understanding code history, and finding who to ask about specific code. Options like -M and -C detect moved and copied code across files to show original authorship rather than the person who relocated it. Line ranges can be specified with -L to focus on specific sections, and -w ignores whitespace changes to find meaningful modifications. The output is invaluable for debugging, code review, and understanding the evolution of specific code sections.

How do I run a basic git-blame example?

Run `git blame [file.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -L _START_,_END_ do in git-blame?

Annotate specific line range.