Linux command
git-annotate 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Show line-by-line authorship
git annotate [file]
Annotate specific revision
git annotate [revision] -- [file]
Show in porcelain format
git annotate --porcelain [file]
Ignore whitespace changes
git annotate -w [file]
说明
git annotate displays line-by-line authorship information for a file, showing which commit and author last modified each line. It's functionally equivalent to git blame but uses a slightly different default output format that emphasizes revision information over authorship. For each line in the file, the command displays the abbreviated commit hash, author name, timestamp, line number, and the actual line content. This makes it invaluable for understanding the history of changes, identifying when bugs were introduced, or determining who to ask about specific code sections. The command supports detecting moved and copied code across files using the -M and -C options, following code even when it's been refactored or relocated. The --porcelain format provides machine-readable output suitable for parsing by scripts or tools. While git blame is more commonly used and has become the de facto standard, git annotate remains available as an alias with historically different formatting preferences.
参数
- -L _start,end_
- Annotate specific lines.
- -w
- Ignore whitespace changes.
- --porcelain
- Machine-readable format.
- -M
- Detect moved lines.
- -C
- Detect copied lines.
FAQ
What is the git-annotate command used for?
git annotate displays line-by-line authorship information for a file, showing which commit and author last modified each line. It's functionally equivalent to git blame but uses a slightly different default output format that emphasizes revision information over authorship. For each line in the file, the command displays the abbreviated commit hash, author name, timestamp, line number, and the actual line content. This makes it invaluable for understanding the history of changes, identifying when bugs were introduced, or determining who to ask about specific code sections. The command supports detecting moved and copied code across files using the -M and -C options, following code even when it's been refactored or relocated. The --porcelain format provides machine-readable output suitable for parsing by scripts or tools. While git blame is more commonly used and has become the de facto standard, git annotate remains available as an alias with historically different formatting preferences.
How do I run a basic git-annotate example?
Run `git annotate [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -L _start,end_ do in git-annotate?
Annotate specific lines.