Skip to content

Instantly share code, notes, and snippets.

@bestK
Last active March 28, 2024 00:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bestK/bf56d7fc20f10daae692c5c9450476a9 to your computer and use it in GitHub Desktop.
Save bestK/bf56d7fc20f10daae692c5c9450476a9 to your computer and use it in GitHub Desktop.
找回git丢失的文件
#!/bin/bash
#@author liukl
# 设置要搜索的目录
search_dir="/path/to/your_project/.git/objects"
# 切换到当前目录
cd "$search_dir"
# 列出当前目录下的所有子目录
for dir in *; do
cd $search_dir/$dir
for file in *; do
# 确保当前项目是文件
if [ -f "$file" ]; then
filename=$(basename "$file")
filepath="$dir$filename"
content=$(git cat-file -p "$filepath")
echo "$content" >> ../找回文件.txt
fi
done
# 返回上一级目录
cd ..
done
yes "-" | sed '102q' | tr -d "\n" && echo
echo Done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment