Skip to content

blameFile

Creates a blame object for the file at the given path

Signature

ts
class Repository {
  blameFile(path: string, options?: BlameOptions): Blame;
}

Parameters

  • pathrequired · string

    Path to the file to blame

  • optionsnull | BlameOptions

    Options to control blame behavior

    • firstParentboolean

      Restrict search to commits reachable following only first parents.

    • ignoreWhitespaceboolean

      Ignore whitespace differences.

    • maxLinenumber

      The maximum line number to blame (1-based index)

    • minLinenumber

      The minimum line number to blame (1-based index)

    • newestCommitstring

      The oid of the newest commit to consider. The blame algorithm will stop when this commit is reached.

    • oldestCommitstring

      The oid of the oldest commit to consider. The blame algorithm will stop when this commit is reached.

    • pathstring

      The path to the file being worked on. Path has to be relative to the repo root.

    • trackCopiesAnyCommitCopiesboolean

      Track lines that have been copied from another file that exists in any commit.

    • trackCopiesSameCommitCopiesboolean

      Track lines that have been copied from another file that exists in the same commit.

    • trackCopiesSameCommitMovesboolean

      Track lines that have moved across files in the same commit.

    • trackLinesMovementboolean

      Track lines that have moved within a file. This is the git-blame -M option.

    • useMailmapboolean

      Use mailmap file to map author and committer names and email addresses to canonical real names and email addresses.

Returns

  • Blame

    Blame object for the specified file

Errors

  • Error

    If the file doesn't exist or can't be opened

Examples

ts
// Blame the entire file
const blame = repo.blameFile('path/to/file.js');

// Blame a single line
const lineBlame = repo.blameFile('path/to/file.js', { minLine: 10, maxLine: 10 });

// Blame a range of lines
const rangeBlame = repo.blameFile('path/to/file.js', { minLine: 5, maxLine: 15 });

Released under the MIT License.