2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

開発中のcommit履歴を全部消してからリリースしたい

Posted at

monwrapというMongoDBラッパーをNPMで公開しました。
公開前にtravisCIでテストを行うのですが、MongoDBを使ったテストは初めてなので.travis.yml(設定ファイル)の書き方がよくわからない。でもGitHubに上げてみないとCIテストができない。
そんなわけでゴミコミットが増えてしまうのを見越して、コミットログが汚れない方法を探ってみました。

1. 別ブランチに退避する

最終的に公開するのがmasterブランチの場合、一旦別のブランチに退避します。masterブランチは後で作り直す為に削除します。

git checkout -b dev
git branch --delete master

警告が出てdaleteできない場合はgit branch -D masterで強制削除できます。自己責任でお願いします。

2. GitHubにpushして作業する

CIの動作確認など、GitHubにpushして作業します。ローカルだけでコミット履歴を消したい時はこの作業は不要です。

3. commit履歴のないmasterブランチを切る

git checkout --orphan master
git commit -m "Initial Commit"
git push -u origin master

git branch --delete dev
git push --delete origin dev

git checkout --orphan master

masterブランチを作りつつcheckoutを行いますが、--orphanオプションを指定するとcommitを引き継がないブランチになります。

git commit -m "Initial Commit"

--orphanオプションでcheckoutするとファイルがステージングされた状態になりますのでそのままcommitします。

git push -u origin master

masterをトラッキングブランチに設定しつつpush

git branch --delete dev

不要になったブランチを削除

git push --delete origin dev

リモート(GitHub)のdevブランチも削除します。しかしここでエラー。

To github.com:mick-whats/mongo.w.git
 ! [remote rejected] dev (refusing to delete the current branch: refs/heads/dev)

GitHubのDefault branchがdevブランチになっているので削除できないようです。

githubのsettings → branches からDefault branchをmasterに変更すると成功しました。

参考

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?