{"id":110234,"date":"2024-09-09T07:00:00","date_gmt":"2024-09-09T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=110234"},"modified":"2024-09-09T09:19:52","modified_gmt":"2024-09-09T16:19:52","slug":"20240909-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240909-00\/?p=110234","title":{"rendered":"GitHub trick to find the commit that deleted a file"},"content":{"rendered":"<p>A common problem in git is finding the commit that deleted a file. <a href=\"https:\/\/stackoverflow.com\/questions\/6839398\/find-when-a-file-was-deleted-in-git\"> The mechanism for doing this in a local repo is well-known<\/a>:<\/p>\n<pre>git log -- path\/to\/deleted\/file\r\n<\/pre>\n<p>There are variations on this command to control how hard you want to look, and which branch you want to look in, but that&#8217;s the basic idea.<\/p>\n<p>But what if you want to do this on a hosted repo?<\/p>\n<p>For GitHub, you can ask for the history of a file in a branch, and the secret is that GitHub doesn&#8217;t mind when you specify a deleted file.<\/p>\n<p><tt> https:\/\/github.com\/<wbr \/>\u27e6user\u27e7\/<wbr \/>\u27e6project\u27e7\/<wbr \/>commits\/<wbr \/>\u27e6branch\u27e7\/<wbr \/>\u27e6path\/<wbr \/>to\/<wbr \/>deleted\/<wbr \/>file\u27e7 <\/tt><\/p>\n<p>For example, to find the commit that deleted <tt>Samples\/<wbr \/>ApplicationData\/<wbr \/>cs\/<wbr \/>Scenario5_<wbr \/>DataChangedEvent.<wbr \/>xaml.<wbr \/>cs<\/tt> from the <tt>main<\/tt> branch of the UWP Samples Repo at <a href=\"https:\/\/github.com\/microsoft\/Windows-universal-samples\/\"> <tt>https:\/\/github.com\/<wbr \/>microsoft\/<wbr \/>Windows-universal-samples\/<\/tt><\/a>, you can go to <tt> <a href=\"https:\/\/github.com\/microsoft\/Windows-universal-samples\/commits\/main\/Samples\/ApplicationData\/cs\/Scenario5_DataChangedEvent.xaml.cs\">https:\/\/github.com\/<wbr \/>microsoft\/<wbr \/>Windows-universal-samples\/<wbr \/>commits\/<wbr \/>main\/<wbr \/>Samples\/<wbr \/>ApplicationData\/<wbr \/>cs\/<wbr \/>Scenario5_<wbr \/>DataChangedEvent.xaml.cs<\/a> <\/tt><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ask for the history of the file.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-110234","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Ask for the history of the file.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=110234"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110234\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=110234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=110234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=110234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}