如何使用本地历史记录更新我的远程“源/主” 如果要保留在 remote/master 上的提交应该最后出现:如果要在 remote/master 上保留的提交应该在开始时出现:

问题描述

上下文:

没有其他人提交过。

我创建了一个分支以在某一时刻恢复,然后继续进行编辑。 我的本地 Master 和本地历史记录目前是我想要在 repo 中生活和记住的“真相”。

但是,当我尝试推送它时,它被远程 Origin/Master 拒绝,然后我尝试拉动它,它也失败了(见截图)。

我真的很想保留我的本地历史记录并远程保存,仅此而已。

谢谢你的光芒!

enter image description here

解决方法

是否要保留 remote/master 上的以下提交:

* Lots of search..
* Replace all..
* Replace all..
* Committing additional ..
* Committing all files..
* Fixes to try to restore site

如果答案是否定的并且不应该保留所有这些提交,那么只需执行以下操作:

git checkout master // To make sure you are on the local master branch
git push -f // Force push your local master to remote/master

如果答案是 YES 并且所有这些提交都应该被保留,那么您首先需要将 rebase local master 放到 remote/master 上,如下所示:

如果要保留在 remote/master 上的提交应该最后出现:

git checkout origin/master // To make sure you are on the remote/master branch
git rebase master // we rebase remote/master to local master
                  // At this point,you might have some conflicts so follow the
                  // guide the rebase offers to resolve them
git push -f       // Force pushing the remote/master

如果要在 remote/master 上保留的提交应该在开始时出现:

git checkout master // To make sure you are on the local branch
git rebase origin/master // we rebase local master to remote master
                  // At this point,you might have some conflicts so follow the
                  // guide the rebase offers to resolve them
git push -f       // Force pushing the local master

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...