Skip to content

Instantly share code, notes, and snippets.

@lsongdev
Last active February 15, 2016 13:07
Show Gist options
  • Save lsongdev/519b7c005a3d6f7827ec to your computer and use it in GitHub Desktop.
Save lsongdev/519b7c005a3d6f7827ec to your computer and use it in GitHub Desktop.
recover your git added without commit file back .
#!/bin/bash
#
filename=$(basename $0 ".sh")
mkdir -p $filename
for blob in $(find .git/objects -type f); do
hash=$(echo $blob | cut -c14- | sed 's|/||')
git show $hash | cat > "$filename/$hash"
done
#!/bin/bash
#
filename=$(basename $0 ".sh")
mkdir -p $filename
ls-tree(){
local hash=$1
type=$(git cat-file -t $hash)
if [ "$type" == "tree" ]; then
blob=$(git ls-tree $hash)
IFS=$'\n'
for line in $blob; do
echo $line
# blob=$(echo $line | awk '{ print $3 }')
# echo $blob
# file=$(echo $line | awk '{ print $2 }')
# ls-tree $blob
done
fi
}
ls-tree "d8521e4ab8eeccd923e2c382410bb3c64c5b12bf"
#
# for file in $(find .git/objects -type f); do
# hash=$(echo $file | cut -c14- | sed 's|/||')
# ls-tree $hash
# # type=$(git cat-file -t $hash)
# # if [ "$type" == "tree" ]; then
# # ls-tree $hash
# # blob=$(git ls-tree $hash | awk '{ print $3,$4 }')
# # git ls-tree $hash
# # IFS=$'\n'
# # for line in $blob; do
# # blob=$(echo $line | awk '{ print $1 }')
# # file=$(echo $line | awk '{ print $2 }')
# # mkdir -p
# # git show $blob | cat > "$filename/$blob-$file"
# # done
# # fi
# done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment