Skip to content

Instantly share code, notes, and snippets.

@hidsh
Last active November 8, 2020 21:01
Show Gist options
  • Save hidsh/27eec3ea29d917a91d397fa23180fe02 to your computer and use it in GitHub Desktop.
Save hidsh/27eec3ea29d917a91d397fa23180fe02 to your computer and use it in GitHub Desktop.
git でそのファイルのすべての版を落としてくる。どこでおかしくなったか探すときにいちいち git checkout COMMIT_NUM -- hoge.txt とか繰り返すのがめんどいので書いた。リグレッションテストのお供に。
#!/bin/sh
help() {
script=`basename $0`
echo "USAGE: $script FILENAME"
echo "Equivalent to: git checkout ALL-COMMITS -- FILENAME"
}
if [ $# -ne 1 ]; then
help
exit 0
fi
git_opt="log --graph --date-order --all --oneline"
filename=$1
# commid_id_bak=`git show -s --format=%H`
# git checkout master > /dev/null 2>&1
list=`git $git_opt -- $filename | cut -f 2 -d " "`
if [ -f $filename ]; then
dt=`date "+%Y%m%d-%H%M%S"`
mv $filename $filename.bak-$dt
fi
i=0
for hash in $list; do
git checkout $hash -- $filename > /dev/null 2>&1
if [ $? -eq 0 ]; then
dest=$i-$hash-$filename
echo "--> $dest"
mv $filename $i-$hash-$filename
else
echo " x $i-$hash NOT FOUND \"$filename\""
fi
i=`expr $i + 1`
done
# git checkout $commid_id_bak
❯❯❯ git-dig.sh hoge.txt
--> 0-1b6afef-hoge.txt
--> 1-c3f1ec8-hoge.txt
x 2-0da650a NOT FOUND "hoge.txt"
--> 3-d1a8b5d-hoge.txt
--> 4-5b4f4dd-hoge.txt
--> 5-76f334e-hoge.txt
漁ってきたファイル名: 番号-コミットID-元のファイル名
           (番号は 0:最近のもの .. 999:古いもの)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment