Finding lost changes with git fsck

Another tool exists in Git that can help you find and recover lost commits and even blobs (files), which is git fsck. The fsck command tests the object database and verifies the SHA-1 ID of the objects and the connections they make. The command can also be used to find objects that are not reachable from any named reference, as it tests all the objects found in the database, which are under the .git/objects folder.

Getting ready

Again, we'll use the hello world repository. If you make a fresh clone, make sure to run the scripts for this chapter (04_undo_dirty.sh), so there will be some objects for git fsck to consider. The scripts can be found on the book's homepage. If you just reset the master branch after performing ...

Get Git: Mastering Version Control now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.