Skip to content

Instantly share code, notes, and snippets.

@irof
Last active June 8, 2021 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irof/fcab7b3d4aeb3eccc29f05f1ceca989e to your computer and use it in GitHub Desktop.
Save irof/fcab7b3d4aeb3eccc29f05f1ceca989e to your computer and use it in GitHub Desktop.
Gitでミスったときのリカバリコマンド

実行方法

curl -L https://gist.githubusercontent.com/irof/fcab7b3d4aeb3eccc29f05f1ceca989e/raw/ac88bd536cf413ea885e0d47d331675d67bc906a/git-recovery.sh | sh

元ネタ

https://twitter.com/suke_masa/status/1402118266546384896

動機

remoteのurl覚えておかなきゃだし削除するディレクトリ名とかも忘れるのでコピペでいけるようにしたかった。

感想

  • rm -rf ./$dirname が怖い
  • このURLとか思い出すの面倒
  • 実行後のディレクトリが変なことになる(カレントディレクトリ消してるからね・・・)
  • だいたい消さなくてもリカバリできる

から、きっと使うことはない。

originUrl=$(git remote get-url origin)
dirname=$(basename $(pwd))
cd ../
rm -rf ./$dirname
git clone $originUrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment