3
2

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.

【Git】マージコミットを取り消す方法

Last updated at Posted at 2024-01-26

どうもこんにちは。

今回はわかりづらい「マージコミットを取り消す方法」を調べましたのでメモします。

通常のコミットとマージコミットの違い

通常のコミットは、修正をしたコードを修正ブランチへ反映させるという意味を持ちます。

マージコミットは、修正が反映されたブランチをmasterブランチやdevelopブランチへマージした時に生じるコミットです。

マージコミットを取り消す手順

今回はdevelopブランチからaa11bb22cc33dd44ee55というコミットIDを持つコミットを取り消す想定で話を進めます。

1. マージを取り消したいブランチへ移動する

git checkout develop

2. revertする

git revert -m 1 aa11bb22cc33dd44ee55

これでマージコミットが取り消されました。-mがないとマージコミットの取り消しができないので注意してください。

revertコマンドについて解説

-mの後の1は、以下のMerge項目のff66gg77を指す「親番号」となります。

% git show aa11bb22cc33dd44ee55
commit aa11bb22cc33dd44ee55
Merge: ff66gg77 hh88ii99
Author: test_user <test_user@mail.com>
Date:   Fri Jan 19 17:10:33 2024 +0900

    コミットメッセージ

スクリーンショット 2024-01-25 12.37.16.png

以上

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?