Last active
March 28, 2024 00:55
-
-
Save bestK/bf56d7fc20f10daae692c5c9450476a9 to your computer and use it in GitHub Desktop.
找回git丢失的文件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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