基本的な使い方

git stash              # 変更を退避
git stash list         # 退避一覧を確認
git stash pop          # 最新の退避を復元して削除
git stash apply        # 最新の退避を復元(削除しない)
git stash drop         # 最新の退避を削除
git stash clear        # 全ての退避を削除

よくある使い方

# 作業中に緊急対応が必要になった場合
git stash
git switch hotfix
# 緊急対応してコミット
git switch main
git stash pop

ハマったポイント

  • git stash pop はコンフリクトが起きることがある
  • 新規ファイルは -u オプションが必要
  • git stash clear は元に戻せないので注意

関連記事