SlideShare a Scribd company logo
1 of 13
git コンフリクト
グラフで視覚化してみよう
x a
x
Alice
Bob
Remote
x
x
git clone
git clone
あるところにAliceとBobという
開発者がいました。
二人はとあるレポジトリから
ソースをCloneしました。
x
Alice
Bob
Remote
x
x
AliceとBobはそれぞれ同じ
ファイルの同じ行に変更を
加えました。
x
Alice
Bob
Remote
x
x
b
git add test.txt
git commit -m “Alice changed it”
git add test.txt
git commit -m “Bob changed it”
a
Aliceはローカルのレポジト
リに変更をコミットしまし
た。
Bobも同じようにはローカ
ルのレポジトリに変更をコ
ミットしました。
x
Alice
Bob
Remote
x
x
b
a
a
git push
まず、Aliceが先に彼女のレ
ポジトリを中央レポジトリ
にプッシュしました。
x
Alice
Bob
Remote
x
x
b
a
a
git push 次に、Bobが彼のレポジト
リを中央レポジトリにプッ
シュしましたが・・・エ
ラーになりました。
x
Alice
Bob
Remote
x
x
b
a
a
git pull
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the
result.
a
エラーの内容:
コンフリクトです。マージしよう
と試みましたが出来ませんでした。
自分でなんとか直してください。
プッシュを断られたので、プルし
ます。するとエラーが出ました。
x
Alice
Bob
Remote
x
x
b
a
a
a
コンフリクトが発生した
ファイルを開けるとこんな
感じでした。
x
Alice
Bob
Remote
x
x
b
a
a
a
仕方がないので、BobはAliceの変
更も反映するように書き直しまし
た。
この作業を手動マージといいます。
x
Alice
Bob
Remote
x
x
a
a
a
git add test.txt
git commit -m “Alice and Bob changed it”
b c
Bobは手動でマージして変更した
ファイルをまたコミットしました。
彼のレポジトリには
Aliceの変更
Bobの変更
手動マージの変更
の三つのコミットが見えます。
x
Alice
Bob
Remote
x
x
a
a
a
b c
b c
git push
Bobが彼のレポジトリを中
央レポジトリにプッシュし
ました。
エラーは出ませんでした。
x
Alice
Bob
Remote
x
x
a
a
a
b c
b c
git pull
b c
ちなみに、Aliceが中央レポ
ジトリの最新の状態をプル
しました。
これで二人の作業が時系列
にそってきちんと保存され
ました。
xRemote a b c
x a
b c
それぞれのコミットのファ
イルの状態は時系列にそっ
て記録されています。

More Related Content

More from Yoshi Watanabe

Create images with AI models.pptx
Create images with AI models.pptxCreate images with AI models.pptx
Create images with AI models.pptxYoshi Watanabe
 
Find n th fibonacci iteratively - illustrated walkthrough
Find n th fibonacci iteratively - illustrated walkthroughFind n th fibonacci iteratively - illustrated walkthrough
Find n th fibonacci iteratively - illustrated walkthroughYoshi Watanabe
 
Binary search: illustrated step-by-step walk through
Binary search: illustrated step-by-step walk throughBinary search: illustrated step-by-step walk through
Binary search: illustrated step-by-step walk throughYoshi Watanabe
 
Quicksort: illustrated step-by-step walk through
Quicksort: illustrated step-by-step walk throughQuicksort: illustrated step-by-step walk through
Quicksort: illustrated step-by-step walk throughYoshi Watanabe
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughYoshi Watanabe
 

More from Yoshi Watanabe (6)

Create images with AI models.pptx
Create images with AI models.pptxCreate images with AI models.pptx
Create images with AI models.pptx
 
Git リベース
Git リベースGit リベース
Git リベース
 
Find n th fibonacci iteratively - illustrated walkthrough
Find n th fibonacci iteratively - illustrated walkthroughFind n th fibonacci iteratively - illustrated walkthrough
Find n th fibonacci iteratively - illustrated walkthrough
 
Binary search: illustrated step-by-step walk through
Binary search: illustrated step-by-step walk throughBinary search: illustrated step-by-step walk through
Binary search: illustrated step-by-step walk through
 
Quicksort: illustrated step-by-step walk through
Quicksort: illustrated step-by-step walk throughQuicksort: illustrated step-by-step walk through
Quicksort: illustrated step-by-step walk through
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk through
 

Git コンフリクト