マージの衝突を解決

マージの衝突を解決
#15 マージの衝突を解決してみよう (1)
http://dotinstall.com/lessons/basic_git/6715
を参考に
マージの衝突を解決する
新しくブランチをつくって
さらに、そのブランチに移動する
つまり checkout まで行うには
git checkout -b hogehoge
というようにすればOK
書式としては
git checkout -b ブランチ名
となる
確認のため
git branch とすると
hoge
* hogehoge
master
となっていて
作成した hogehoge に移動しているのが確認できる
ここからは git のマージの衝突を実行
vim index.html
でファイルを
line1 から line first へ変更して保存
git add .
でインデックス化して
git commit -m “not 1 but fitst”
とすることで
vim を起動せずにリポジトリに保存
ここまではいままでと同じ
ここからが衝突
まず、ブランチを hogehoge から master に変えるので
git checkout master
そして、 vim index.html で編集
中身は、ブランチごとにわけられているので
line1
をmaster のほうでは
line 1st
と変更して保存
そして、同じように
git add .
git commit -m “not 1 but 1st”
と実行
この状態でマージすると衝突が発生する
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
このように、問題発生して
解決しないと git commit できないという状況になる
この解決方法が動画で紹介されているのが
#16 マージの衝突を解決してみよう (2)
http://dotinstall.com/lessons/basic_git/6716
のほう
現状をまずは git status で確認
# On branch master
# Unmerged paths:
# (use “git add/rm …” as appropriate to mark resolution)
#
# both modified: index.html
#
no changes added to commit (use “git add” and/or “git commit -a”)
とメッセージがでて
修正を促される
このため、vim index.html でファイルを修正する
ファイルを開くと
<<<<<<< HEAD line 1st ======= line first >>>>>>> hogehoge
line2
となっている
現在のブランチは master のほうで
<<<<<<< HEAD line 1st ======= が master のほう line first >>>>>>> hogehoge
line2
が hogehoge ブランチのほうで
このうちどちらかを残すか、もしくは修正することになる
今回は master のほうを残しておきたいので
修正するには
<<<<<<< HEAD line 1st ======= line first >>>>>>> hogehoge
line2

line 1st
line2
というように、いらない部分を削除して保存
あとは git add .
git commit -m “confilict fixed”
というように、ふつうに git commit できるようになる
確認するには
git log

commit 734665444c30621d32b3800d56ffd1dcd5583201
Merge: 6379343 a989662
Author: snowpool
Date: Thu May 30 20:09:07 2013 +0900
confilict fixed
commit 637934389be80431ac468343f50129bb0a587018
Author: snowpool
Date: Thu May 30 19:57:21 2013 +0900
not 1 but 1st
commit a989662710cb5542428878d9de9028c89920c2f7
Author: snowpool
Date: Thu May 30 19:52:36 2013 +0900
not 1 but fitst
commit cce3862b9c30a544c772e675ccd5f6a98e345022
Author: snowpool
Date: Thu May 30 07:02:34 2013 +0900
script added
commit 1110869d4bef57d3502c434ad9f4a94c8633242f
Author: snowpool
Date: Wed May 29 20:55:00 2013 +0900
line2 を追加
commit 53d156650c331b31b33c8907f25527e61978dfcf
Author: snowpool
Date: Tue May 28 21:28:11 2013 +0900
initial commit
(END)
commit a989662710cb5542428878d9de9028c89920c2f7
Author: snowpool
Date: Thu May 30 19:52:36 2013 +0900
not 1 but fitst
以下略
というように
commit できているのが確認できる

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です