背景
Gitでコンフリクトが発生した際、--theirs
と --ours
オプションを使用して、どの変更を採用するかを指定できる。
Gitでコンフリクトが発生した際、--theirs
と --ours
オプションを使用して、どの変更を採用するかを指定できる。
--theirs
と --ours
の意味はコマンドごとに異なる。merge
, rebase
, cherry-pick
, revert
を扱う。$ git checkout feature
$ git merge main
# main の内容を採用
$ git checkout --theirs [file]
# feature の内容を採用
$ git checkout --ours [file]
$ git checkout feature
$ git rebase main
# main の内容を採用
$ git checkout --ours [file]
# feature の内容を採用
$ git checkout --theirs [file]
$ git checkout feature
$ git cherry-pick <commit_hash>
# cherry-pick するコミットの内容を採用
$ git checkout --theirs [file]
# feature ブランチの内容を採用
$ git checkout --ours [file]
$ git revert <commit> <commit> ...
# リバートするコミットの内容を採用
$ git checkout --theirs [file]
# 現在のブランチの内容を採用
$ git checkout --ours [file]
コマンド | --theirs の内容 | --ours の内容 |
---|---|---|
merge | マージ元(main) | 現在のブランチ(feature) |
rebase | リベース先(main) | 現在のブランチ(feature) |
cherry-pick | 適用するコミット | 現在のブランチ(feature) |
revert | リバートするコミット | 現在のブランチ |