Git 并强制接受来自其他分支的更改

Git and forcing to accept changes from other branch

我正在尝试将一个分支合并到 master 中,但无论如何都想确保来自另一个分支的所有更改都生效,但不确定如何进行?主要问题是我们最终在 50 个文件中发生合并冲突,我们不关心 master 之前的状态。

故事:master 分支维护了 2018 年的一个版本,而 2019 年版本的工作在另一个分支中完成。 2019 年的变化很复杂,由于运行时环境依赖变化的影响,需要放弃 2018 年变化的很大一部分。我们现在想要从 2019 年开始进行所有更改,并使它们成为新的 master 状态。

到目前为止我尝试过的(作为单独的尝试):

git merge 2019-release
git merge -X theirs 2019-release
git merge -s recursive -X theirs 2019-release

最后一个似乎更好,但遇到重命名和删除文件的问题,因为我们包含的框架已被重写,所以有很多文件。

想知道是否采用一种焦土式的方法来掌握(清除所有文件并提交),然后进行合并是另一种方法吗?

我确实尝试查看 Stack Overflow,但没有找到似乎可以正确解决问题的答案。

有什么建议吗?

您要查找的内容与您上次尝试的内容接近。

git merge -X ours(甚至 git merge -s recursive -X ours)使用 ours 端自动解决 冲突 。 (doc)

git merge -s ours 从接收分支获取 所有内容 ,无论冲突与否,因此完全丢弃来自 theirs 方的更改。

奇怪的是,页面中相应的段落有相同的锚点link,一定是一个小错误,但一定要检查两个条目并比较。我不能 link 最相关的一个,因为它也指向另一个,但它说:

This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches. Note that this is different from the -Xours option to the recursive merge strategy.


等等

# we have to work from the 2019-release side since there is no theirs version for -s
git checkout 2019-release
git merge -s ours master

# at this point we have to reflect the operation on master
# (the second merge is just a fast-forward)
git checkout master
git merge 2019-release

这将从 2019-release 端获取 一切 ,并且仍然将操作标记为合并,尽管有些人可能认为这在技术上是覆盖.