简体   繁体   English

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

[英]Git and forcing to accept changes from other branch

I am trying to merge a branch into master, but want to ensure all changes from the other branch take effect, no matter what, but not sure how to go about it?我正在尝试将一个分支合并到 master 中,但无论如何都想确保来自另一个分支的所有更改生效,但不知道该怎么做? The main issue is that we are ending up with merge conflicts in 50 files, where we don't care about the previous state of master.主要问题是我们最终会在 50 个文件中发生合并冲突,我们不关心 master 的先前状态。

The story: The master branch had been maintained for a release in 2018, while work for 2019 release had been done in another branch.故事:master 分支已经在 2018 年的一个版本中得到维护,而 2019 年版本的工作已经在另一个分支中完成。 The changes in the 2019 are complex and required throwing away a good portion of the 2018 changes, because of impacts of runtime environment dependency changes.由于运行时环境依赖项更改的影响,2019 年的更改很复杂,需要丢弃 2018 年更改的很大一部分。 We now want to take all the changes from 2019 and make them the new state of master.我们现在想要采用 2019 年的所有更改,并使它们成为 master 的新状态。

What I have tried so far (as separate attempts):到目前为止我尝试过的(作为单独的尝试):

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

The last one seems better, but runs into issues with renamed and deleted files, which there are many of, since the framework we include has been rewritten.最后一个看起来更好,但遇到了重命名和删除文件的问题,因为我们包含的框架已被重写,因此有很多问题。

Wondering whether to do a scorched-earth type of approach to master (clearing all files and committing), followed by a merge would be an alternative approach?想知道是否采用焦土类型的方法来掌握(清除所有文件并提交),然后进行合并是另一种方法吗?

I did try looking around Stack Overflow, but haven't found an answer that seems to properly address the issue.我确实尝试环顾 Stack Overflow,但还没有找到似乎可以正确解决该问题的答案。

Any suggestions would be appreciated?任何建议,将不胜感激?

What you're looking for is close to the last one you tried.您正在寻找的内容与您尝试的最后一个内容相近。

git merge -X ours (or even git merge -s recursive -X ours ) automatically resolve conflicts using ours side. git merge -X ours (甚至git merge -s recursive -X ours )使用ours一方自动解决冲突 ( doc ) ( 文档)

git merge -s ours takes everything from the receiving branch, conflicts or not, thus completely discarding changes from theirs side. git merge -s ours从接收分支中获取所有内容,无论是否发生冲突,从而完全丢弃theirs方面的更改。

Oddly, the corresponding paragraphs in the page have the same anchor link, must be a minor bug, but be sure to check both entries and compare .奇怪的是,页面中对应的段落有相同的锚链接,一定是一个小错误,但一定要检查两个条目并进行比较 I couldn't link the most relevant one since it also points to the other but it says :我无法链接最相关的一个,因为它也指向另一个,但它说:

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.请注意,这与递归合并策略的 -Xours 选项不同。


And so所以

# 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

This will take everything from 2019-release side, and still mark the operation as a merge, although some might argue this is technically an overwrite.这将采取2019-release方面的所有内容,并将操作标记为合并,尽管有些人可能会认为这在技术上是覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GIT:将更改从一个分支移动到另一个分支 - GIT: Move changes from one branch to other Git复制从一个分支更改为另一个 - Git copy changes from 1 branch to the other Git将更改从分支的提交应用于其他分支的现有提交 - Git apply changes from a commit of a branch to an existing commit of other branch Git将master合并到分支并接受部分更改 - Git merge master to branch and accept partial changes 是否可以将一些更改从一个 git 分支部署到其他分支? - Is it possible to deploy some changes from one git branch to other? 在git中将特定文件的更改从一个分支合并到另一个分支 - Merge changes to specific file from one branch to other in git 在git merge期间,在合并冲突的情况下,如何接受来自某个分支的所有更改? - During git merge, in the case of merge conflict, how do I accept all changes from a certain branch? 将 git 分支的更改恢复到主分支 - Revert changes from a git branch to the master branch 使用git将“导入”从一个分支更改为一个重新创建的分支 - “Importing” changes from a branch to a rebased branch with git 如何让 github 分支接受从其他分支推送的更改,但它一直说没有什么可以提交? - How to get a github branch to accept changes pushed from other branches but it keeps saying that there is nothing to commit?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM