Skip to content

Instantly share code, notes, and snippets.

@joakin
Last active February 25, 2026 15:40
Show Gist options
  • Select an option

  • Save joakin/67f5afdd083ccfb8fecd to your computer and use it in GitHub Desktop.

Select an option

Save joakin/67f5afdd083ccfb8fecd to your computer and use it in GitHub Desktop.
finding a deleted file in a git repository
# If you don't remember the exact path/name, search the log for deleted files
git log --diff-filter=D --summary | grep delete
# Find the file you want to get from the ouput, and use the path
# Find the commits that involved that path
git log --all -- some/path/to/deleted.file
# Bring the file back to life to the current repo (sha commit of parent of commit that deleted)
git checkout shaofthecommitthatdeletedthefile^ -- some/path/to/deleted.file
@einav7

einav7 commented Apr 20, 2021

Copy link
Copy Markdown

thank you! :-)

@rgab1508

rgab1508 commented Sep 8, 2021

Copy link
Copy Markdown

thnx bruh

@feeschmidts

Copy link
Copy Markdown

This has been so helpful! Thank you!

@shofwan

shofwan commented Oct 8, 2021

Copy link
Copy Markdown

what is this g co? I can't run this command

@joakin

joakin commented Oct 8, 2021

Copy link
Copy Markdown
Author

@shofwan a git checkout alias I have. I’ll clarify

@yudi-azvd

Copy link
Copy Markdown

Really helpful

@smitsrr

smitsrr commented Jun 14, 2022

Copy link
Copy Markdown

Thanks! This was super helpful!

@darrenmk

Copy link
Copy Markdown

thank you!

@mappingvermont

Copy link
Copy Markdown

Amazing - thank you!

@Basem-Gaber

Copy link
Copy Markdown

Helpful 👍

@vfesenkoupgrade

Copy link
Copy Markdown

The first command shows me the deleted file path but the second returns nothing

@monsilaro

monsilaro commented Mar 22, 2023

Copy link
Copy Markdown

nice thanks

@Eben-Hafkamp

Copy link
Copy Markdown

Cheers!

@kevineleven

Copy link
Copy Markdown

Awesome, thank you.

@shaunsim15

Copy link
Copy Markdown

2nd command was helpful for me, thanks!

@TheVonyo

TheVonyo commented Aug 1, 2023

Copy link
Copy Markdown

so nice !

@Pascal1515

Copy link
Copy Markdown

Thanks!!!

@bryanwhiting

Copy link
Copy Markdown

beautiful

@simxn1

simxn1 commented Oct 10, 2023

Copy link
Copy Markdown

Thanks!

@djoble-koutouan-shift

Copy link
Copy Markdown

🚀

@andifreed

Copy link
Copy Markdown

love the script name.

@aqeelat

aqeelat commented Jul 10, 2024

Copy link
Copy Markdown

Shukran

@andrewgunn

Copy link
Copy Markdown

Legend!

@mAlhotraHArsHit

Copy link
Copy Markdown

The script name is a beauty !

@laneschmidt

Copy link
Copy Markdown

Big shouts

@vincemann

Copy link
Copy Markdown

based

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment