1
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 1 year has passed since last update.

mergeコミットを取り消す(git revertする)

Last updated at Posted at 2022-07-06

mergeされたコミットを取り消す(git revertする)

基本的にはgit revertするだけではあるが、mergeされたコミットのrevertは-mオプションによりmergeされた側かmergeした側かを指定する必要がある。

通常のrevertコマンド

$ git revert { mergeコミットのcommit id }

mergeされたコミットのrevertコマンド

https://qiita.com/t-vinn/items/537c2236e56ef389133b
そこで、 -m オプションが必要になります。
-m は mainline の略で、2つの履歴のどちらをmainlineとして残したいかを 1 か 2 で指定します。
1 がマージされた側のブランチ(今回でいうとabcブランチ)、2がマージした側のブランチ(今回でいうとmasterブランチ)を指します。
今回のようにmergeコミットをrevertしたい場合は、1を指定すればOKです。

$ git revert -m 1 { mergeコミットのcommit id }

参考

1
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
1
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?