How do I find a file that may have exited in a Git repo sometime in the past?

  • Page Owner: Not Set
  • Last Reviewed: 2018-10-25

I just cloned a repo of a .NET class library. This a library I wrote, and have made almost 200 commits to over the last four years.

It wouldn't build because it said it couldn't find FilterLoading.cs which was a class file in the test project (presumably filled with a bunch of unit tests to verify filter loading is working correctly).

Visual Studio was showing an explanation point over the icon in Solution Explorer, which means a reference to this file was in the .csproj, but the file wasn't on the file system and, therefore, wasn't in the repo.

But why would there be a reference in the project file? It had to have existed at some point (the name certainly sounds familiar), and I can't figure out why it isn't there now. I'm nervous that I lost a bunch of unit tests somehow (I still have 80 tests from other files, but I don't remember if that number is right).

How can I ask Git if it's ever seen this file before, and when did it disappear?

It's a public repo, BTW: https://github.com/deanebarker/Denina-Sharp


Additional Posts

It looks like there are a lot of ways to do this. The best one I could find is: git log -- some_path/FilterLoading.cs. The problem is that we don't know what the path is. In order to discover the path I ran git log --name-only |grep FilterLoading.cs in order to discover the path of the file FilterLoading.cs (the --name-only flag returns the filenames of each commit). After discovering the full path of the file, we could run a git log using the full path.

After downloading your project, it looks like that file was never versioned in the project. There was a CustomFilterLoading.cs previously, but never FilterLoading.cs. To view the git log of the similar file run:

git log  -- Tests/CustomFilterLoading.cs

Comments

  • This is my preferred way to find historic files in repos, not because it is the most direct answer, but because git log -- {file} and git log --name-only + / are so useful on their own, they're easy to remember to combine to do this.
  • Note also that git log will take globs, so you don't have to know your full exact filename and use git log with search... and you can also search all branches/tags/stashes/etc with git log... Try this git log --full-history --name-only --all -- **/*FilterLoading.cs .