DEV Community

Cover image for Count number of files deleted between Git commits
Adam K Dean
Adam K Dean

Posted on

1

Count number of files deleted between Git commits

To count the number of files deleted between two Git commits, use the following command:

$ git log --diff-filter=D --summary 45b0487..HEAD | grep 'delete mode' | wc -l

Be sure to change 45b0487 to the commit you want to count from, or remove 45b0487..HEAD altogether to look through the entire history.

We use grep to count the number of deleted files.

$ git log --diff-filter=D --summary | grep 'delete mode'

delete mode 100644 test (3).txt
delete mode 100644 test (4).txt
delete mode 100644 test (2).txt

Then we use wc -l to do a line count:

$ git log --diff-filter=D --summary | grep 'delete mode' | wc -l
      3

Sometimes you get whitespace back from wc -l, you can trim that with tr:

$ git log --diff-filter=D --summary | grep 'delete mode' | wc -l | tr -d ' '

3

This may take some time for larger repositories.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

ACI image

ACI.dev: The Only MCP Server Your AI Agents Need

ACI.dev’s open-source tool-use platform and Unified MCP Server turns 600+ functions into two simple MCP tools on one server—search and execute. Comes with multi-tenant auth and natural-language permission scopes. 100% open-source under Apache 2.0.

Star our GitHub!

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay