LoginSignup
14
13

More than 5 years have passed since last update.

Git rebaseした結果を強制的にリモートブランチに書き込みたいとき

Posted at

以前に何回かrebaseはしたことがあったのですが、いつもやり方を忘れてしまうので、メモ。たぶんそこら中に同じような記事が載っているので私のはあまり参考になりません。ほんとにただのメモです。
今回はrebaseしてコミットログを書き換えたはいいけどもう既にpushしちゃってるんですけどというシナリオ。あるあるですね。

まずrebase

git rebase -i HEAD~4

でインタラクティブモードに入って

コミットログを書き換えたいコミットを pick から e に変更します。
vimを保存して終了。

次は

git commit ––amend

でコミットログの修正。終わったら保存。これでコミットが修正されます。

で、以下のコマンドで次のコミットに移動

git rebase ––continue

最後までやったら

Successfully rebased and updated refs/heads/master.

と出るのでこれで完了。

リモートブランチにpushする

––force オプションで強制的にリモートブランチにpushします。

git push ––force

ただし、このやりかたをするならそのリモートブランチが自分以外ほとんどいじる機会がないことを確認してからやるのがいいかもしれません。他の人が頻繁にpush, pullしてるブランチにこれをやったらどうなるかは想像もつきません。

参考文献

14
13
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
14
13