Home > Enterprise >  git - how to find commits which reference specific file extensions that do NOT exist in the source c
git - how to find commits which reference specific file extensions that do NOT exist in the source c

Time:11-03

I need to find all commits in git log which are referencing some old binaries with extensions .jar and .class.

We did have those files in the source code but not anymore! However, I need to find all the commits which were referencing some of the files with that extension (for example test.class although I do not know the exact names of those files, just their extensions). I need to filter the commits that did some modification on files with extension .class for example. I do NOT want to filter commits based on the commit message.

I tried with:

git log --oneline -- '*.class'

in relation to this link: Using git to see all logs related to a specific file extension within subdirectories

but without luck (no result)

Is this my requirement achievable? Thanks a lot!

CodePudding user response:

Git stores every commit forever (or for as long as you can find its hash ID), and every commit stores every file forever. So all the information you want is in the repository, and you're on the right track:

git log --oneline -- '*.class'

The problem you encounter here is that this kind of git log operation works by filtering away some commits. That is, git log visits the commits—i.e., the history—but doesn't tell you about some of them. The commits are the history, and if git log didn't filter some away like this, you'd get all the non-relevant commits.

So far, no problem, but: this kind of filtering is what Git calls history simplfication, and if you bring up the git log documentation and search for History Simplification (this direct link may stop working at some point, but works at the moment to go straight to it), you'll find this:

Default mode
Simplifies the history to the simplest history explaining the final state of the tree. [emphasis mine]

Since the "final state of the tree" has the *.class files removed, git log here often doesn't bother telling you about commits that added and modified the files. They're gone! You clearly don't care about them!

  •  Tags:  
  • git
  • Related