LoginSignup
1
2

More than 3 years have passed since last update.

Git コンフリクト 解消方法

Last updated at Posted at 2021-02-04

共同開発をしていると必ずと言っていいほど起こる現象ですね! 笑
慌てず落ちついてすればなんの問題もないので大丈夫です。
それでは行きましょー!!

内容

スクリーンショット 2020-12-13 20.42.52.png

手順

master(マージ先)を最新の状態にする
ブランチの切り替え

$ git checkout master

リモートの状態を反映させる
$ git pull 

作業ブランチに戻り

$ git checkout 作業ブランチ名

以下を実行する。

$ git fetch
$ git merge origin/master

するとコンフリクトが発生しているよと知らせてくれます。

Auto-merging db/schema.rb
CONFLICT (content): Merge conflict in db/schema.rb
Auto-merging config/routes.rb
Auto-merging app/views/layouts/application.html.erb
CONFLICT (content): Merge conflict in app/views/layouts/application.html.erb
Auto-merging app/assets/stylesheets/application.scss
CONFLICT (content): Merge conflict in app/assets/stylesheets/application.scss
Automatic merge failed; fix conflicts and then commit the result.

コンフリクトが発生している箇所を見て見ましょう!

CONFLICT (content): Merge conflict in app/views/layouts/application.html.erb

スクリーンショット 2020-12-13 20.47.24.png

エディタを開くと紫色で表示されていると思うのでわかりやすいと思います。 (vscode使用しています)

<<<<<<< HEAD
# 作業ブランチでの変更内容
・・・
=======
# origin/master(マージしたブランチ)での変更内容
・・・
>>>>>>> origin/master

master(最新)を残し作業ブランチの内容を削除する

こちらも忘れず削除しましょう!
<<<<<<< HEAD

=======

>>>>>>> origin/master

コンフリクトが発生している箇所の修正が完了したら
コミットとプッシュ

git commit -m "コンフリクト解消"

git push origin 作業ブランチ名
これで大丈夫です。ww
1
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
1
2