LoginSignup
0
2

More than 5 years have passed since last update.

git rebase後のpushを間違った時の対処

Posted at

なぜgit rebaseをしたのか

github上のPR上でissueの解決を進めていました。
いざmasterにmergeできるかと思った際に、masterよりかなり遅れている作業branchであったことがわかったためrebaseを行ないました。

rebaseの開始

$ git rebase master

これでrebaseを開始できます。
その後、conflictが発生したため、修正→git rebase --continue/skipということを行なった。

$ git rebase --continue

// if nothing to change but still rebase is not finised,
// rebaseが終わらなかったらskipで加えて進めていきました。

$ git rebase --skip

// conflictが生じたらその都度修正していきます。

最終的にrebaseしているbranchの内容を作業branchにapplyすることになり以下のように行いました。

$ git add .
$ git commit -m "fix: something"
$ git push

しかし、
commits.jpg

このようにcommitが膨れ上がってしまいました。ありゃありゃ。

解決策

$ git reset --hard HEAD~4  // rebase前のコミットへ変更しました。

$ vim src/...  // ファイルを編集するなどしてエラーを消します。

$ git add .  // 変更を加えてコンフリクトもなくなれば、コミットします。
$ git commit -m "fix: errors"
$ git push --force  // ここのpush --forceであるのを忘れないように。

// 必要であれば
$ git cherry-pick  // rebaseの後のコミットの変更を反映してもいいかと。

反省

git rebase --continue をした時にgit push --forceをする必要がありました。
少ないコミットで綺麗なPRを心がけていきます。

参考文献

git push の取り消し方法
チュートリアル3 コミットを書き換えよう!4. cherry-pick

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