.git-blame-ignore-revs is a Git feature introduced in version 2.23 that allows you to ignore specific commits in git blame results. This is particularly useful for bulk commits that change a large number of lines without altering the actual functionality of the code, such as formatting changes, renaming, or applying coding standards across a codebase. By ignoring these non-functional changes, git blame can focus on meaningful edits that explain the context and reasoning behind the code.
Why .git-blame-ignore-revs Matters
When you use git blame on a file, it shows you which commit last changed each line of the file, along with the author and timestamp. This is useful for tracking down why a particular line was changed. However, if a large commit that makes purely formatting changes, like applying prettier, is part of the history, git blame may point to that commit for many lines. This make it difficult to find the actual functional change history.
For example, if your team uses a tool like Prettier or ESLint to reformat the entire codebase, the resulting commit might touch thousands of lines of code. Without .git-blame-ignore-revs, git blame would show this commit as responsible for every affected line, which could obscure the more meaningful history behind each line.
By using .git-blame-ignore-revs, you can tell git blame to skip over these commits and focus on the changes that matter.
How to Use .git-blame-ignore-revs
To understand how to use this feature, let’s walk through an example from the React repository.
Step 1: Identify the Bulk Formatting Commits
The React source code includes bulk commits where tools like Prettier were run across the entire project. Here are two such commits:
- Commit: c998bb1 Message: [compiler] Run prettier, fix snap This commit applies Prettier formatting across the codebase, altering many lines without changing the functionality.
2. Commit: fd2b3e1
Message: Compiler: Unfork prettier config
This commit contains further updates to the Prettier configuration, affecting all .ts and .tsx files in the repository.
These commits only deal with formatting and don’t provide meaningful context when investigating why a line of code was written the way it was.
Step 2: Create the .git-blame-ignore-revs File
To make git blame ignore these bulk formatting commits, we can create a .git-blame-ignore-revs file in the root of the repository.
- Create the .git-blame-ignore-revs file:
touch .git-blame-ignore-revs
2. Add the relevant commit hashes to the file, explaining why each commit is being ignored. In this case, we’ll add the two commits we identified earlier:
# Prettier formatting changes c998bb1ed4b3285398c9c7797135d3f060243c6a fd2b3e13d330a4559f5aa21462e1cb2cbbcf144b
3. Save the .git-blame-ignore-revs file in the repository. This file can be versioned alongside your code, allowing the entire team to use the same list of ignored commits.
Step 3: Configure Git to Use .git-blame-ignore-revs
To avoid typing the --ignore-revs-file option every time you use git blame, you can configure Git to automatically use the .git-blame-ignore-revs file.
- Set up the configuration at the repository level:
git config blame.ignoreRevsFile .git-blame-ignore-revs
This ensures that every time someone runs git blame in this repository, Git will automatically ignore the commits listed in .git-blame-ignore-revs.
Step 4: Run git blame with the Ignored Commits
Let’s see how this works in practice. Without ignoring the bulk formatting commits, git blame might show:
$ git blame src/someFile.tsx c998bb1e (Joe Bloggs 2023-03-15 10:00:00 +0200 1) import React from 'react'; fd2b3e13 (Alan 2023-04-01 14:15:30 +0200 2) function App() { c998bb1e (Joe Bloggs 2023-03-15 10:00:00 +0200 3) return <div>Hello, world!</div>; fd2b3e13 (Ben 2023-04-01 14:15:30 +0200 4) }
This output indicates that the last change to lines 1 and 3 was due to the Prettier formatting commit (c998bb1e), and lines 2 and 4 were modified in another bulk commit (fd2b3e13). Since these are formatting changes, this is not helpful for understanding who introduced the actual logic behind these lines.
After configuring .git-blame-ignore-revs, running git blame will skip the bulk commits and show the real history:
$ git blame src/someFile.tsx a23d9b34 (May 2022-12-01 09:30:00 +0200 1) import React from 'react'; b12e45a6 (JJ 2022-12-05 11:45:15 +0200 2) function App() { a23d9b34 (Joe 2022-12-01 09:30:00 +0200 3) return <div>Hello, world!</div>; b12e45a6 (Ram 2022-12-05 11:45:15 +0200 4) }
Now, git blame attributes the lines to the correct commits, ignoring the unimportant formatting changes. This gives us useful information, showing who made the actual functional changes.
Conclusion
The .git-blame-ignore-revs feature in Git 2.23 is a game-changer for projects with bulk formatting or style changes. By setting up a .git-blame-ignore-revs file and configuring your repository, you can apply coding standards, run tools like Prettier, or refactor code without worrying about polluting the blame history.
With this approach, your team can confidently improve code quality and formatting without sacrificing the ability to track meaningful changes, ensuring that git blame remains a valuable tool for understanding the history and reasoning behind each line of code.
About us:
At Think Throo, we are on a mission to teach the advanced codebase architectural concepts used in open-source projects.
10x your coding skills by practising advanced architectural concepts in Next.js/React, learn the best practices and build production-grade projects.
We are open source — https://github.com/thinkthroo/thinkthroo (Do give us a star!)
Up skill your team with our advanced courses based on codebase architecture. Reach out to us at hello@thinkthroo.com to learn more!
References:
https://github.com/facebook/react/blob/main/.git-blame-ignore-revs
https://gist.github.com/kateinoigakukun/b0bc920e587851bfffa98b9e279175f2
https://github.com/facebook/react/commit/c998bb1ed4b3285398c9c7797135d3f060243c6a
https://moxio.com/blog/ignoring-bulk-change-commits-with-git-blame/
The above is the detailed content of `.git-blame-ignore-revs` to ignore bulk formatting changes.. For more information, please follow other related articles on the PHP Chinese website!

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.