git - 用 develop 覆盖 master

标签 git merge git-merge merge-conflict-resolution

在我们的项目中,我们的 master 分支是如何完全崩溃的。它认为它领先于一些提交,如果我们尝试 merge 开发,它会显示大量的冲突。它已经坏了很长时间了,所以在开发中发生了很多事情(太多的冲突需要解决)。

我只想用 develop 覆盖 master 中的所有内容(因此 master 基本上等于 develop)。我该怎么做?

我试过在本地删除 master 中的所有内容,然后运行以下命令:

git checkout master
git reset --hard develop

似乎给了我所有正确的文件,但是当我尝试推送 master 时,我得到了这个错误:

Updates were rejected because the tip of your current branch is behind

最佳答案

I want to just overwrite everything in master with develop (so master basically equals develop). How do I do this?

--force git-branch 的选项将完全做到这一点:

git checkout develop
git branch -f master develop

请注意在修改 master 之前需要切换到不同的分支,因为 git-branch将拒绝更改当前分支。

或者,您可以使用 git-update-ref plumbing command :

git update-ref refs/heads/master refs/heads/develop

它允许您修改任何引用,无论 HEAD 当前指向何处。请注意 git-update-ref 将参数视为 file paths relative to the .git directory .

最后,您需要使用 -f --force git-push 的选项重写远程 master 分支:

git push -f origin master

来自documentation :

Usually, "git push" refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it.

This option overrides this restriction if the current value of the remote ref is the expected value. "git push" fails otherwise.

关于git - 用 develop 覆盖 master,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50796204/

相关文章:

git - rebase 后到 "pull"或 "push" fork 分支?

Eclipse,重命名项目删除了所有 git 存储库

git - `git log --name-only` 显示合作者

git - 更改 git 远程之间的提交用户

java - 合并具有重复键的 map 列表

git - IntelliJ 理念 : Disable Auto Commit on Merge

git - 您如何 merge 已还原的提交?

python - 在属性 ID 相同的地方合并 XML 文件 Python

git:为什么我不能在 Squash merge 后删除我的分支?

Git merge 忽略空格