Skip to content
A Python script to help recover lost files following a mistaken 'git reset --hard' command.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
recover_git_blobs.py

README.md

git-reset-head-file-recover

A Python script to try recover lost files following a mistaken 'git reset --hard' command.

Disclaimer

This software does not, in any way promise to recover any of your files. It simply provides a mechanism for which to try and recover files yet to be removed by the git garbage collector.

The author takes no responsibility or liability for any damages to files, software or hardware caused as a result of using this software.

Credits

This project is heavily based on an existing Python script provided by user 'Boy' over at StackOverflow.

Usage

  1. Ask Git to list all "unreachable blobs" (i.e. files not added/commit and now unreachable) and pipe this to a file.

     git fsck --cache --unreachable $(git for-each-ref --format="%(objectname)") > <export_filename>
    
  2. Run the Python script.

     python recover_git_blobs.py <export_filename>
    
  3. The script will export a collection of files containing the contents of each cached "unreachable blob". The user can then search through the contents of these files in order to try and find the file they wish to recover.

You can’t perform that action at this time.