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

[Git] 動作を試す 実行例32:revertでマージを明示的に打ち消して戻す

Last updated at Posted at 2023-05-18

Gitの動作を理解するために、Gitのコマンドを実際に試して、結果を見てみました。

1つの記事内で一連のGitコマンドが完結しているので、これら一連のコマンドを順に実行させて結果を見ることで、一連のGitの動作を実際に体感でき、一通り独習することが可能です。

※前回記事のリポジトリ状態からの続きになっています。

前回記事へ 目次へ:Git関連記事のまとめページ 次回記事へ

実行例

dir /b
↓
結果: 
test1.txt
test10.txt
test2.txt
test4.txt

※マージコミットを明示的に打ち消して戻す(新しいコミットを作る)
※-m 1 or 2オプションで、保持すべき「メイン」の親がどれであるかを指定
git revert -m 1 HEAD --no-edit
↓
結果: 
[branch1 ed89b19] Revert "Merge branch 'master' into branch1"
 Date: Sun Jan 1 18:52:53 2023 +0900
 3 files changed, 2 insertions(+), 5 deletions(-)
 delete mode 100644 test10.txt

git show -s
↓
結果: 
commit ed89b19b2700e54c315d9e453e0c0803dab6b717 (HEAD -> branch1)
Author: person1 <person1@abc.def>
Date:   Sun Jan 1 18:52:53 2023 +0900

    Revert "Merge branch 'master' into branch1"

    This reverts commit 135f847ec431e2a07484d9a1b70a75022bb4e953, reversing
    changes made to 2495cae5d5c421e418d91d4053489c05ba9a2703.

git log --oneline --graph --all
↓
結果: 
* ed89b19 (HEAD -> branch1) Revert "Merge branch 'master' into branch1"
*   135f847 Merge branch 'master' into branch1
|\
| * 60b0341 (master) message12
| * 045a734 message11
| * d10f934 message10
* | 2495cae message7
|/
| * b838160 (branch2) message9
| * c68ef01 message8
|/
* 94996a0 message4
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1

dir /b
↓
結果: 
test1.txt
test2.txt
test4.txt

type test1.txt
↓
結果: 
Sample-Added-11
Sample-Added-12
Sample-Added-13
Sample-Added-14
Sample-Added-17

※branch1側に戻る

-----

(※1つ前=始めの状態に戻す)
git reset --hard "HEAD^"
type test1.txt
↓
結果: 
Sample-Added-11
Sample-Added-12
Sample-Added-13
Sample-Added-14
Sample-Added-17+110+111

-----

git revert -m 2 HEAD --no-edit
↓
結果: 
[branch1 116f132] Revert "Merge branch 'master' into branch1"
 Date: Sun Jan 1 18:55:53 2023 +0900
 1 file changed, 2 insertions(+), 1 deletion(-)

type test1.txt
↓
結果: 
Sample-Added-11
Sample-Added-12
Sample-Added-13
Sample-Added-14
Sample-Added-110
Sample-Added-111

※master側に戻る

-----

(※1つ前=始めの状態に戻す)
git reset --hard "HEAD^"
type test1.txt
↓
結果: 
Sample-Added-11
Sample-Added-12
Sample-Added-13
Sample-Added-14
Sample-Added-17+110+111

環境

Windows 10、PortableGit-2.40.0-64-bitを使用、全てローカルPC上で実施、GitHub等は不使用。

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