2
0

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 3 years have passed since last update.

Gitのcherry-pickを取り消す

Last updated at Posted at 2020-11-24

cherry-pickで反映したコミットは「git reset」コマンドで取り消すことができる。

$ git reset --hard HEAD~

cherry-pickしたブランチをリモートに上げてしまっている場合、取り消ししたブランチをpushしようとすると以下のようなエラーになってしまう。

$ git push origin master
To https://gitlab.com/hoge/hogehoge.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitlab.com/hoge/hogehoge.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

これを回避するため、pushする際は「-f」オプションをつける必要がある。

$ git push -f origin master

※「git reset」コマンドを使用する場合ログに残らないので、残したい場合は「git revert」コマンドを使用する

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?