Scott Whittaker

Frontend Developer

Day job React | side projects Svelte

Find recent commits of a given file type using git

A handy git snippet for finding recent commits of certain file types.

git log --since="1 month ago" --diff-filter=A --name-only -- '*.png'
  • git log displays the commit logs.
  • --since="1 month ago" filters the commits to only show those made in the last month.
  • --diff-filter=A filters the log to show only files that were added (A) in the commits.
  • --name-only shows only the names of the files affected by the commits, not the full diff.
  • -- '*.png' limits the search to files with a .png extension.

Context

For context, this was useful in a scenario where I was investigating startup time of a web application. An issue had been raised noting that the main bundle was 500kB for example. When checking the application myself I noticed the main bundle was a lot bigger than this so something had been added to the repo since the time of the report.

At this point in my investigation I was aware that all the images in the application were inlined, which means embedding the images directly into CSS or JavaScript files as Base64-encoded strings, rather than linking to external image files. This approach had been fine early in the project but is now problematic as larger image files can excessively bloat the bundle when Base64-encoded as strings.

My hunch was there must have been more images added in recent weeks that were causing the large increase in bundle size. It would not have been that hard to look through recent git history and look for any images that had been added but in the spirit of laziness this is far more pleasing. Thus, I am leaving this here for future me to maybe save a second or 2 of valuable time should I need to do this again.