Files
git/Documentation
Ravi Mistry 52890fcfd4 blame: ignore revs in .git-blame-ignore-revs by default
git-blame(1) can ignore a list of commits specified via
--ignore-revs-file or the blame.ignoreRevsFile configuration variable.
This is useful for skipping uninteresting revisions such as tree-wide
formatting changes, large-scale refactors, and code modernizations that
would otherwise obscure genuine historical authorship.

When revision-ignoring was introduced in commit ae3f36dea1 ("blame: add
blame.ignoreRevsFile config option", 2019-10-18), it intentionally
avoided adopting a default ignore file. At the time, the capability was
new and unproven, so avoiding unrequested filesystem I/O or unexpected
attribution shifts took priority over a project-wide default.
Requiring explicit opt-in per clone was therefore the prudent design.

Since then, maintaining a .git-blame-ignore-revs file at the top level
of the repository has become the standard convention across the Git
ecosystem, adopted by many open source projects (such as Chromium and
LLVM) as well as hosting platforms (GitHub, GitLab, Gerrit). However,
git-blame(1) and git-annotate(1) still ignore this file unless each
user remembers to manually configure blame.ignoreRevsFile in every
local clone.

Teach git-blame(1) and git-annotate(1) to automatically add
.git-blame-ignore-revs, if it exists, as the initial element in the
list of ignore-revs files. Similar to how read_mailmap() handles
.mailmap, consult .git-blame-ignore-revs at the root of the working
tree when a working tree is available, and otherwise consult the
HEAD:.git-blame-ignore-revs blob in bare repositories. Reading only
from the working tree in non-bare repositories makes it ergonomic to
prepare a new .git-blame-ignore-revs file, edit an existing one, or
remove a committed one and immediately test the effect with
git-blame(1) before committing, while consulting
HEAD:.git-blame-ignore-revs in bare repositories allows them to
respect the committed ignore list as well.

To ensure consistent precedence, override semantics, and safety when
reading upstream-controlled content:
- The default .git-blame-ignore-revs entry is added before reading
  configuration and CLI options, preserving user and repository config
  overrides.
- In git_blame_config(), blame.ignoreRevsFile entries are appended via
  string_list_append() rather than inserted in sorted order via
  string_list_insert() so that configuration entries preserve their
  order relative to the initial default entry.
- When a working tree is present, the working-tree
  .git-blame-ignore-revs path is checked with lstat() and S_ISREG(),
  opened with open_nofollow(), and verified with fstat() and S_ISREG()
  so symbolic links and non-regular files are silently skipped. In bare
  repositories, HEAD:.git-blame-ignore-revs is resolved quietly via
  get_oid_with_context() and its tree entry mode is checked with
  S_ISREG() before checking the object.
- In both modes, the file or blob size is capped at
  IGNORE_REVS_MAX_FILE_SIZE (100MB, matching ATTR_MAX_FILE_SIZE from
  3c50032ff5 ("attr: ignore overly large gitattributes files",
  2022-12-01)) before reading its contents, skipping an oversized file
  or blob with a warning without loading it into memory. The contents
  are parsed via a new oidset_parse_buffer_carefully() helper in
  oidset.c that shares line parsing with oidset_parse_file_carefully().
- In build_ignorelist(), ignore-revs entries are processed starting
  after the last empty string entry. This ensures setting
  blame.ignoreRevsFile to "" or passing --ignore-revs-file "" or
  --no-ignore-revs-file cleanly discards the default entry without
  attempting to read or parse it, allowing users to bypass a malformed
  default ignore-revs file.

Update documentation in blame-options.adoc and config/blame.adoc, and
add test coverage in t8013 for the default working-tree lookup,
uncommitted and untracked .git-blame-ignore-revs files, subdirectory
invocations, bare repositories, CLI and config overrides, symbolic
links, overly large files and blobs, and comments and whitespace
handling.

Based-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>
Helped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Ravi Mistry <rmistry@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-10-13 13:35:24 -07:00
..
2026-10-06 10:13:32 -07:00
2025-03-01 10:26:15 -08:00
…
2025-12-14 17:04:37 +09:00
2026-10-01 11:26:40 -07:00
2025-02-14 17:53:47 -08:00
2025-12-16 09:42:44 +09:00
…