Table of contents

Categories

Category cover

Automation
155 posts

Category cover

Learning paths
119 posts

Category cover

CISO
22 posts

Category cover

Security
20 posts

Category cover

Notes
19 posts

Category cover

Personal Security
18 posts

Category cover

Infrastructure
12 posts

Category cover

OT/ICS
5 posts

Category cover

Books
3 posts

Category cover

UNetLab
3 posts

Category cover

Write-up
3 posts

Category cover

OSInt
2 posts

Category cover

My life
1 posts

Find and recover deleted files on Git repository

Andrea Dainese
September 19, 2018
Post cover

Git repositories are very interesting from an OSInt perspective. There are a few commands to find out deleted files and recover them in seconds:

# Find deleted files
git log --diff-filter D --pretty="format:" --name-only | sed '/^$/d' > deleted_files.txt

# Find the associated commit
while read line; do git rev-list HEAD -n 1 -- $line | tr '\n' ' '; echo $line; done < deleted_files.txt > deleted_commits.txt

# Restore files
while read line; do git checkout $(echo $line | cut -d" " -f1)^  $(echo $line | cut -d" " -f2); done < deleted_commits.txt