Skip to content

Add optional Git blame annotations for working-tree files - #3991

Open
Matei02355 wants to merge 2 commits into
sharkdp:masterfrom
Matei02355:git-blame-1536-20260907
Open

Add optional Git blame annotations for working-tree files#3991
Matei02355 wants to merge 2 commits into
sharkdp:masterfrom
Matei02355:git-blame-1536-20260907

Conversation

@Matei02355

Copy link
Copy Markdown
Contributor

Show commit attribution before line numbers with --blame or the blame style component. Keep it opt-in, including when using the full style, and expose the same controls through PrettyPrinter.

Use gix's blame support to follow renames and merge history, then map HEAD attribution onto the current worktree with Git's clean-filter pipeline. Insertions, modifications and staged changes are marked uncommitted; unchanged lines retain their original commits. Handle linked worktrees, unborn repositories, untracked files and CRLF conversion. Preserve physical attribution when ranges, squeezing or nonblank numbering change the displayed line numbers.

Add --blame-format for commit hashes, author/committer names, emails, dates, Unix times and subjects. Sanitize metadata, truncate by Unicode grapheme boundaries to a bounded sidebar width, and leave wrapped continuation annotations empty. Ordinary UTF-8 files are supported; stdin, preprocessing, unbuffered input, binary files and files outside repositories omit attribution. History is computed before printing, so large histories can delay initial output.

This revisits the static blame feature proposed by @userwiths in #2851, which was welcomed after a rebase and later closed as stale. The implementation uses the repository's current gix dependency, enabling its blame feature and adding gix-blame 0.16.0.

Validation: all 487 all-feature tests passed (7 ignored), including 14 regressions comparing attribution against git blame across edits, renames, merges, worktrees and CRLF conversion. All 8 default-feature help tests passed. All-target/all-feature Clippy with warnings denied, formatting, whitespace checks, Bash/Zsh completion syntax, and a library build without Git or paging passed. README, manual, help snapshots and all four completions are updated. GitHub CI will validate other platforms.

Fixes #1536. Fixes #2810.

@Matei02355
Matei02355 marked this pull request as ready for review September 7, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add optional git blame to file output Add a flag to show git blame

1 participant