LoginSignup
0
1

More than 3 years have passed since last update.

rebase時のコンフリクトでリベース先の変更だけ適用する方法

Posted at

Rebase対応にて、コンフリクトした場合、リベース先の変更を全て取り入れる場合

いろいろあって、リベース先の変更を全て入れないといけなかったのでメモ

TL;DR

git checkout --ours <ファイルパス>
git add <ファイルパス>
# コンフリクト全て対象で良いなら、<ファイルパス>部分を . 指定でOK

検証してみる

まずmasterブランチで何もないファイルを作成してcommit

devブランチを切る

$ git checkout -b dev

devブランチでsample.txtを以下の内容で保存

sample.txt
aaa

masterブランチに移動してsample.txtを以下の内容で保存

sample.txt
bbb

これでコンフリクトする。

devブランチに移動してrebase

$ git rebase master

バッチリコンフリクトした

$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: change sample.txt on dev
Using index info to reconstruct a base tree...
M       sample.txt
Falling back to patching base and 3-way merge...
Auto-merging sample.txt
CONFLICT (content): Merge conflict in sample.txt
error: Failed to merge in the changes.
Patch failed at 0001 change sample.txt on dev
hint: Use 'git am --show-current-patch' to see the failed patch
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".

リベース先の変更を入れる

今回の場合はmasterブランチの内容を入れる

$ git checkout --ours sample.txt
$ git add sample.txt

これでOK!

ちなみに...

rebase元(今回で言うとdevブランチ)の内容を反映する場合は、

$ git checkout --theirs sample.txt
$ git add sample.txt

で良い。

0
1
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
1