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] 動作を試す 実行例34:mergeコマンドを用いて更に複数回マージしてみる

Posted at

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

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

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

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

実行例

(※始めにコミット履歴状況を確認)
git log --oneline --graph --all
↓
結果: 
* f3ef64d (HEAD -> branch2) message12
* 7fdeb04 message10
* b838160 message9
* c68ef01 message8
| *   135f847 (branch1) Merge branch 'master' into branch1
| |\
| | * 60b0341 (master) message12
| | * 045a734 message11
| | * d10f934 message10
| |/
|/|
| * 2495cae message7
|/
* 94996a0 message4
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1

-----

※更にマージしてみる: master ← branch2
git checkout master
git merge branch2
↓
結果: 
Auto-merging test1.txt
CONFLICT (content): Merge conflict in test1.txt
Auto-merging test10.txt
CONFLICT (add/add): Merge conflict in test10.txt
Automatic merge failed; fix conflicts and then commit the result.

git status -s
↓
結果: 
UU test1.txt
AA test10.txt

git diff -U3
↓
結果: 
diff --cc test1.txt
index 2b06b09,8a7ca86..0000000
--- a/test1.txt
+++ b/test1.txt
@@@ -2,5 -2,6 +2,11 @@@ Sample-Added-1
  Sample-Added-12
  Sample-Added-13
  Sample-Added-14
++<<<<<<< HEAD
 +Sample-Added-110
 +Sample-Added-111
++=======
+ Sample-Added-18
+ Sample-Added-19
+ Sample-Added-110
++>>>>>>> branch2
diff --cc test10.txt
index 002832f,0b7d9ed..0000000
--- a/test10.txt
+++ b/test10.txt
@@@ -1,3 -1,2 +1,6 @@@
  Sample-Added-1010
++<<<<<<< HEAD
 +Sample-Added-1011
++=======
++>>>>>>> branch2
  Sample-Added-1012

(※コンフリクトを手動で解消)
echo Sample-Added-11 > test1.txt
echo Sample-Added-12 >> test1.txt
echo Sample-Added-13 >> test1.txt
echo Sample-Added-14 >> test1.txt
echo Sample-Added-18 >> test1.txt
echo Sample-Added-19 >> test1.txt
echo Sample-Added-110 >> test1.txt
echo Sample-Added-111 >> test1.txt
type test1.txt
↓
結果: 
Sample-Added-11
Sample-Added-12
Sample-Added-13
Sample-Added-14
Sample-Added-18
Sample-Added-19
Sample-Added-110
Sample-Added-111

(※test10.txtのコンフリクトを解消せずに進めてみる)

git add .
git status -s
↓
結果: 
M  test1.txt
M  test10.txt

※マージ処置をコミット
git commit --no-edit
↓
結果: 
[master 4791df6] Merge branch 'branch2'

※test10.txtのコンフリクトを解消せずに進めると、コンフリクト追記状態のままコミットされる
type test10.txt
↓
結果: 
Sample-Added-1010
<<<<<<< HEAD
Sample-Added-1011
=======
>>>>>>> branch2
Sample-Added-1012

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

-----

(※test10.txtのコンフリクトを解消して修正をコミット)
echo Sample-Added-1010 > test10.txt
echo Sample-Added-1011 >> test10.txt
echo Sample-Added-1012 >> test10.txt
type test10.txt
↓
結果: 
Sample-Added-1010
Sample-Added-1011
Sample-Added-1012

git add .
git commit -m "message13 (fixed test10.txt)"
↓
結果: 
[master a4d1247] message13 (fixed test10.txt)
 1 file changed, 3 deletions(-)

git log --oneline --graph --all
↓
結果: 
* a4d1247 (HEAD -> master) message13 (fixed test10.txt)
*   4791df6 Merge branch 'branch2'
|\
| * f3ef64d (branch2) message12
| * 7fdeb04 message10
| * b838160 message9
| * c68ef01 message8
| | *   135f847 (branch1) Merge branch 'master' into branch1
| | |\
| |_|/
|/| |
* | | 60b0341 message12
* | | 045a734 message11
* | | d10f934 message10
|/ /
| * 2495cae message7
|/
* 94996a0 message4
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1

-----

※更にマージしてみる: branch1 ← master
git checkout branch1
git merge master
↓
結果: 
Auto-merging test1.txt
CONFLICT (content): Merge conflict in test1.txt
Automatic merge failed; fix conflicts and then commit the result.

git status -s
↓
結果: 
UU test1.txt

git diff -U3
↓
結果: 
diff --cc test1.txt
index 5b43773,1c2a726..0000000
--- a/test1.txt
+++ b/test1.txt
@@@ -2,4 -2,7 +2,11 @@@ Sample-Added-1
  Sample-Added-12
  Sample-Added-13
  Sample-Added-14
++<<<<<<< HEAD
 +Sample-Added-17+110+111
++=======
+ Sample-Added-18
+ Sample-Added-19
+ Sample-Added-110
+ Sample-Added-111
++>>>>>>> master

(※コンフリクトを手動で解消)
echo Sample-Added-11 > test1.txt
echo Sample-Added-12 >> test1.txt
echo Sample-Added-13 >> test1.txt
echo Sample-Added-14 >> test1.txt
echo Sample-Added-17 >> test1.txt
echo Sample-Added-18 >> test1.txt
echo Sample-Added-19 >> test1.txt
echo Sample-Added-110 >> test1.txt
echo Sample-Added-111 >> test1.txt
type test1.txt
↓
結果: 
Sample-Added-11
Sample-Added-12
Sample-Added-13
Sample-Added-14
Sample-Added-17
Sample-Added-18
Sample-Added-19
Sample-Added-110
Sample-Added-111

git add .
git status -s
↓
結果: 
M  test1.txt

※マージ処置をコミット
git commit --no-edit
↓
結果: 
[branch1 2b19eaa] Merge branch 'master' into branch1

git log --oneline --graph --all
↓
結果: 
*   2b19eaa (HEAD -> branch1) Merge branch 'master' into branch1
|\
| * a4d1247 (master) message13 (fixed test10.txt)
| *   4791df6 Merge branch 'branch2'
| |\
| | * f3ef64d (branch2) message12
| | * 7fdeb04 message10
| | * b838160 message9
| | * c68ef01 message8
* | | 135f847 Merge branch 'master' into branch1
|\| |
| * | 60b0341 message12
| * | 045a734 message11
| * | d10f934 message10
| |/
* / 2495cae message7
|/
* 94996a0 message4
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1

※現在のブランチ構造の模式図(+Mはマージ、10C,12Cはチェリーピック)
message1-2-3-4-10-11-12-+M-13 ←master
             |       ↓ ↑ ↓
             +-7-----+M-↑-+M ←branch1
             |          ↑
             +-8-9-10C--12C ←branch2

-----

※マージのコミットでは、--stat指定時でも、変更したファイル(コンフリクトの解消による変更)が表示されない模様
git log --oneline --graph --all --stat -5
*   2b19eaa (HEAD -> branch1) Merge branch 'master' into branch1
|\
| * a4d1247 (master) message13 (fixed test10.txt)
| |  test10.txt | 3 ---
| |  1 file changed, 3 deletions(-)
| *   4791df6 Merge branch 'branch2'
| |\
| | * f3ef64d (branch2) message12
| | |  test10.txt | 1 +
| | |  1 file changed, 1 insertion(+)
| | * 7fdeb04 message10
| | |  test1.txt  | 1 +
| | |  test10.txt | 1 +
| | |  2 files changed, 2 insertions(+)

-----

※masterとbranch2だけのログを表示
git log --oneline --graph master branch2
↓
結果: 
* a4d1247 (master) message13 (fixed test10.txt)
*   4791df6 Merge branch 'branch2'
|\
| * f3ef64d (branch2) message12
| * 7fdeb04 message10
| * b838160 message9
| * c68ef01 message8
* | 60b0341 message12
* | 045a734 message11
* | d10f934 message10
|/
* 94996a0 message4
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1

環境

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?