在我们的项目中,我们的 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
withdevelop
(somaster
basically equalsdevelop
). 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/