git-recover-lost-index 512 B

12345678910111213
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. # Recover indexed/staged changes that were lost.
  5. #
  6. # Though not commited yet, git actually stores information about staged changes.
  7. # This function locates all dangling/orphaned blobs and puts them in text files.
  8. # These files can then be checked for changes that a user has lost.
  9. # http://blog.ctp.com/2013/11/21/git-recovering-from-mistakes/
  10. for blob in $(git fsck --lost-found | awk '$2 == "blob" { print $3 }'); do
  11. git cat-file -p $blob > $blob.txt;
  12. done