LoginSignup
0
0

More than 1 year has passed since last update.

[基礎]rebase(リベース)したときのコンフリクトの解消方法

Last updated at Posted at 2021-06-08

はじめに

git mergeと違ってリベースをしたときのコンフリクトは各コミットごとに起こるため若干厄介です。
その対処法を見様見真似でやってみたので、こちらでまとめます

準備

まずは準備です。
ブランチを用意して、それぞれで作業していきます

terminal
% git br
* master
 % git br test
 % git br
* master
  test 

index.html
<p>master側の処理です</p>
terminal
% git add index.html
% git commit -m "masterでの処理"

index.html
<p>test側の処理です</p>
terminal
% git add index.html
% git commit -m "testでの処理"

リベースしていく

さっそくリベースしていきます。まずtestブランチで以下を叩きます

terminal
git rebase master

すると以下のような表示が出ます。

Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
error: could not apply c2657f6... test側での処理
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply c2657f6... test側での処理

コンフリクトですね。さっそく手元のコードを見てやります。

index.html
<<<<<<< HEAD
<p>masterでの処理です</p>
=======
<p>test側での処理</p>
>>>>>>> c2657f6 (test側での処理)

今回はあえて次のように処理してやります。

index.html
<p>喧嘩両成敗!!</p>

そして、コミットします。

terminal
git add index.html
git commit -m "リベースのコンフリクト解消1"

git statusして状態を見てやリましょう

terminal
interactive rebase in progress; onto 6d9705c
Last command done (1 command done):
   pick c2657f6 test側での処理
No commands remaining.
You are currently editing a commit while rebasing branch 'test' on '6d9705c'.
  (use "git commit --amend" to amend the current commit)
  (use "git rebase --continue" once you are satisfied with your changes)

nothing to commit, working tree clean

ご丁寧に次にないすべきか書いてあります。
今回はコンフリクトを解消したので、続行させます。

terminal
% git rebase --continue
Successfully rebased and updated refs/heads/test.

よし!!成功!

次にmasterブランチに行きます。

masterブランチでマージしてやります

terminal
git merge test

おわり

コンフリクトは怖いですが絶対にわけわからん!ということはないはずなので落ち着いて対応しましょう!

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