Skip to content

Instantly share code, notes, and snippets.

@sorohan
Last active April 14, 2021 01:21
Show Gist options
  • Save sorohan/7a32b32ad52134fce0055a65aa3942eb to your computer and use it in GitHub Desktop.
Save sorohan/7a32b32ad52134fce0055a65aa3942eb to your computer and use it in GitHub Desktop.
Find a lost file from an orphaned git commit.
file=$1
for f in $(git fsck --lost-found | grep 'dangling commit' | awk '{print $3}'); do
git log --stat $f | grep $file &> /dev/null;
if [ $? -eq 0 ]; then
git log -1 $f;
fi;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment