Read Anthropic’s case study about Graphite Reviewer

Using git blame while ignoring revs

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


git blame shows the revision (commit) and author for each line modified in a file. This can be extremely useful when gathering context on why a particular change was made. However, sometimes you may want to ignore certain commits, especially if they involve formatting changes or large refactors that might obscure the history of who changed specific lines. This guide will explain how to effectively use the git blame --ignore-rev flag to ignore specific revisions.

The git blame command works by iterating through a file's change history to determine who last modified each line. However, some adjustments, lke formatting and style changes might obscure underlying functional changes. This is where ignoring specific revisions becomes useful.

The process to set up git blame to ignore specific revisions involves a few steps. These are crucial to ensure that you are only getting relevant information about the functional changes in your file.

Before modifying any configuration files, you need to decide which commits should be ignored by git blame. These are typically commits that refactor or reformat code without altering functionality.

While you can ignore specific revisions individually with the ignore-rev flag, you can also specify multiple revisions to be ignored at once using a configuration file.

To do this, create a file in your repository where you can list all the commit hashes that should be ignored. A common naming convention for this file is .git-blame-ignore-revs.

Create this file by running the following commands:

Terminal
# Navigate to your repository root
cd path/to/your/repo
# Create the .git-blame-ignore-revs file
touch .git-blame-ignore-revs
# Add the commit hashes of the revisions you wish to ignore
echo "commit_hash_here # Comment about why this commit is ignored" >> .git-blame-ignore-revs

Each commit hash is typically added to this file with a comment explaining why it is ignored. This is not only good practice for record-keeping but also helps maintain clarity in a team environment.

After populating the .git-blame-ignore-revs file with the commits you wish to ignore, you need to configure git to use this file when executing the git blame command.

Terminal
# Set the blame.ignoreRevsFile configuration in your local git config
git config blame.ignoreRevsFile .git-blame-ignore-revs

This command tells git to reference the specified file for commits to ignore when you run git blame. This configuration can also be set globally or system-wide by using --global or --system.

Once you've configured git blame with the ignore-revs file, you can run git blame as you normally would:

Terminal
git blame filename

With the configuration set, git blame will skip over the commits listed in the .git-blame-ignore-revs file, giving you a clearer picture of who made meaningful changes to the file.

  • Review periodically: Over time, as more refactoring or formatting commits are added, it's a good practice to update the .git-blame-ignore-revs file.
  • Sharing configurations: If you're working in a team, it's helpful to share the blame configuration settings by committing the .git-blame-ignore-revs file and ensuring everyone sets up their git config accordingly.

For further reading on git blame see the official Git documentation.

0 min read
0
Share
Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2