Skip to content

Instantly share code, notes, and snippets.

@taea
Last active December 14, 2015 00:59
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 taea/5002760 to your computer and use it in GitHub Desktop.
Save taea/5002760 to your computer and use it in GitHub Desktop.
いらんcommitをpushしてしまった時の黒魔術

該当するbranchに移動

$ git checkout hogebranch

過去いくつかのcommitをgit rebase -i(下記の場合は7個)

$ git rebase -i HEAD~~~~~~~

git rebase -i HEAD~7という書き方でもOK)

エディタが立ち上がる

pick eafa87e Remove hogehoge
pick e4ff1a5 Kick out hogehoge
pick 1e5f766 Remove fuga
pick e90e305 Fix design for hogehoge
pick fc1c368 Work in progress
pick 45fd66f Fix fuga
pick a17b335 Fix descriptions of hogehoge

消したいcommitを行ごと消して保存
この場合、"Work in progress" というcommitを消したいので、

pick fc1c368 Work in progress

の行をまるっと消して保存。

※ 別のbranchでは必要なcommitで、かつ、すでに別のbranchにもすでに存在するcommitならば、このbranchから消しても、別branchの方には残ってるので大丈夫。

git log するとcommit消えてるのが確認できる。

おもむろに

$ git push -f  

リモートリポジトリからもcommitが消える。
GitHubのPull Request画面から、消したcommitに関連するコメントとかも消える。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment