Skip to content

Instantly share code, notes, and snippets.

@okash1n
Last active April 14, 2023 15:04
Show Gist options
  • Save okash1n/54ee37a6f7237e7b55dd5e730efeec9a to your computer and use it in GitHub Desktop.
Save okash1n/54ee37a6f7237e7b55dd5e730efeec9a to your computer and use it in GitHub Desktop.
Gitのローカルの現在の状態を最新として過去のコミット履歴を全て削除しリモートにプッシュする黒魔術
# 以下を実行するとローカル、リモートともに "initial commit" の1コミットだけの状態になる。
# 独立したローカルブランチ tmp を作成
git checkout --orphan tmp
# ローカルブランチ tmp に全体を add
git add .
# ローカルブランチ tmp に最初のコミット
git commit -m "initial commit"
# ローカルブランチ main を ローカルブランチ tmp の内容で上書き
git checkout -B main
# リモートブランチ main に強制プッシュ(一つしかコミットの無い新しい main ブランチでリモートブランチを上書き)
git push -f origin main
# ローカルブランチ tmp を削除
git branch -d tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment