4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Git main(master)ブランチなどを別のブランチの内容で上書きマージしたい

Last updated at Posted at 2023-04-17

ユースケース

mainブランチへと、releaseブランチの内容をマージしたい。しかし、mainブランチに直前に別チームの変更内容がマージされていた関係で、releaseブランチとの間にコンフリクトが生じてしまっている。別チームの変更内容は今後不要なので捨てる予定である。そのため、コンフリクトの解除の手間なく、releaseブランチの現在の内容でmainブランチを完全に上書きするという形で、releaseをmainブランチにマージしたい、というようなケース。

方法

git merge -s ours main(sオプションマージ)を使いましょう。

git checkout release
git merge -s ours main
git checkout main
git merge release

参考

Delftstack - Git マスターをブランチで上書きする

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?