LoginSignup
305
234

More than 5 years have passed since last update.

[git]マージ時のコンフリクトで片側の変更だけ適用する方法

Posted at

2つのブランチをマージした際にコンフリクトしたとして、どちらかだけを全面的に適用したい場合はどうするか。

以下のように、checkout --ourscheckout --theirs を使い分ければ良い。

# 2つのブランチ間でコンフリクトしているファイル fileA.txt と fileB.txt があるとする

# fileA.txt を現在チェックアウトしているブランチ側の対応に合わせる場合
$ git checkout --ours fileA.txt
$ git add fileA.txt    # add を忘れずに

# fileB.txt をマージさせたブランチ側に合わせる場合
$ git checkout --theirs fileB.txt
$ git add fileB.txt

$ git commit
305
234
2

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
305
234