如何在Sourcetree中用Dev Branch替换主人
我正在使用 SourceTree。 我有 Dev 分支和 master 分支。 Dev比Master早很多版本,所以如果我合并的话会有很多冲突。
无论如何,我可以将 master 分支中的所有内容替换为 dev 内容吗?
I'm using SourceTree.
I have Dev branch and master branch. Dev is many version ahead of Master so there will be a lot of conflicts if I merge.
Is there anyway I can replace all the content in master branch with the dev content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您试图将开发开发人员合并到主人中时存在合并冲突,那是因为主人对不在dev上的提交。而且,开发人员的提交不是主人。如果此提交更改相同的代码行,则将存在合并冲突。
但是,如果您正确管理主分支和开发分支,则绝对不应存在合并冲突。通常不在主人上的开发人员提交是很常见的。这是开发分支的重点。但是,我唯一不在DEV上提交的是当我制作一个直接合并到主机中以立即修复关键错误的紧急热点时。危机解决后,我将大师合并为开发人员,以避免在常规部署期间进行任何将来的合并冲突。
我的建议是,您将主人合并到开发人员中以解决合并冲突。我认为有任何造成这些冲突的主人的理由。在我必须这样做的极少数情况下,我在开发人员上创建了一个新的分支,然后将主分支合并为其中。这使我能够以一种不会打破开发分支的方式工作。这也使我能够进行后续提交,以防我错过了合并过程中的某些内容。
由于您想保留DEV的更改,因此您可以告诉Git为您做到这一点:
或使用单独的分支:
现在您有一个分支机构可以创建PR
作为最后一个度假胜地,您可以将Master重置为开发人员:
警告:这是破坏性的,如果您搞砸了,基本上是不可能恢复的。因此,大多数GIT托管服务都保护主分支免受力推动。您将必须禁用此保护。完成后,请务必对其进行续签。
If there are merge conflicts when you try to merge dev into master, it is because there are commits on master that aren't on dev. And there are commits on dev that aren't on master. If this commits make changes to the same lines of code, then there will be merge conflicts.
However, if you manage master and dev branches correctly, there should never be merge conflicts. It is common to have commits on dev that aren't on master. This is the whole point of a dev branch. However, the only time I have commits on master that aren't on dev is when I make an emergency hotfix that merges directly into master to fix a critical bug immediately. After the crisis is resolved, I merge master into dev to avoid any future merge conflicts during regular deployments.
My suggestion is that you merge master into dev to resolve merge conflicts. I assume there is a reason for any commits on master that cause these conflicts. In the rare case that I've had to do this, I create a new branch on dev and then merge master into it. This allows me to work in such a way that I don't break the dev branch. This also allows me to make follow up commits in case I missed something in the merge process.
Since you want to keep the changes from dev, you can tell git to do it for you:
or with a separate branch:
Now you have a branch that you can create a PR to master
As a last resort, you can just reset master to dev:
WARNING: This is destructive and basically impossible to recover from if you mess it up. For that reason, most git hosting services protect the master branch from force push. You will have to disable this protection. Be sure to renable it after you finish.