LoginSignup
57
42

More than 5 years have passed since last update.

git のコミット履歴をすべて消す(現時点の状態の1コミットだけにする)

Posted at

普通はこんなことしない。

が、やんごとなき理由によりやらねばならないときに。

git checkout --orphan tmp
git commit -m "Initial Commit"
git checkout -B master
git branch -d tmp

解説

git checkout --orphan tmp

orphan オプションによって、独立した(親を共有していない)ブランチを切ることができる。

git commit -m "Initial Commit"

独立している tmp ブランチにコミット。tmp 上ではこれが最初のコミットとなる。

git checkout -B master

B オプションで master ブランチを上書き。この時点で master ブランチは先程の1コミットログだけが残る。

git branch -d tmp

あとしまつ。

57
42
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
57
42