September 9th, 2024

GitHub trick to find the commit that deleted a file

A common problem in git is finding the commit that deleted a file. The mechanism for doing this in a local repo is well-known:

git log -- path/to/deleted/file

There are variations on this command to control how hard you want to look, and which branch you want to look in, but that’s the basic idea.

But what if you want to do this on a hosted repo?

For GitHub, you can ask for the history of a file in a branch, and the secret is that GitHub doesn’t mind when you specify a deleted file.

https://github.com/⟦user⟧/⟦project⟧/commits/⟦branch⟧/⟦path/to/deleted/file⟧

For example, to find the commit that deleted Samples/ApplicationData/cs/Scenario5_DataChangedEvent.xaml.cs from the main branch of the UWP Samples Repo at https://github.com/microsoft/Windows-universal-samples/, you can go to https://github.com/microsoft/Windows-universal-samples/commits/main/Samples/ApplicationData/cs/Scenario5_DataChangedEvent.xaml.cs

Topics
Other

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

6 comments

Discussion is closed. Login to edit/delete existing comments.

  • deadpin

    This should come in handy for whoever decided to trash the devblogs website with an absolutely horrendous and useless layout. Someone needs to help them find the old files that they probably deleted so sanity can return.

    • alan robinson

      But the web designers need a job, and everybody knows the job of a web designer is to take what’s not broken and make it different. Bonus points if it’s flatter. Since they added some “depth” with the card outline, later on they can remove that in the name of progress.

    • Adam Rosenfield

      * The card layout on the home page is terrible and useless
      * Default comment sort order was changed from oldest first to newest first; I can change the sort order manually, but it doesn't persist if I refresh the page to load new comments, making it nearly useless
      * Comments are truncated at absurdly short lengths, resulting in "Show more" links that you need to click for a 2/3-sentence comment
      * Comment timestamps seem...

      Read more
    • schbaem

      It’s the card layout that is totally useless on a devblog. Who in their right mind would trash the old, clean looking list with the cards? I don’t want this site to look fancy i am searching for information. The new layout is an abysmal nightmare.

      • Sigge Mannen

        The messing with the blog has been mainstay of oldnewthing/microsoft, at least they didn’t remove the old posts and mess up the links like in the old days.
        I gotta admit though, the new new design is aggressively bad, especially the Read more thing. Also, maybe i’m getting older but the font is smaller making it harder to read. One thing which is still great is the actual written material!