git rebase 远程,但在本地保留更改以供以后提交

标签 git git-rebase git-remote

我犯了错误,在主服务器上提交了开发更改,并将它们推向上游。从远程存储库撤消这些更改,但在本地保留分支以便稍后 merge 到主服务器中的最佳方法是什么?

最佳答案

您只需按顺序排列分支,然后进行强制推送:

git checkout master        # though you're probably already there
# create the branch you should've committed to instead of master
git branch local-changes
# put master back where it belongs
git reset --hard <commit-master-should-be-at>
# and push it to origin!
git push -f

所有关于这将如何影响从上游存储库中提取的人的常见警告都适用!

关于git rebase 远程,但在本地保留更改以供以后提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4717700/

相关文章:

git - 'git remote show'详解

git - git pull 后如何解决冲突?

ruby-on-rails - (<unknown>): 在第 3 行第 1 列扫描一个简单键时找不到预期的 ':' (Psych::SyntaxError)

git - 为什么 Jenkins 的 Git 插件用额外的斜杠重写我的本地 git repo url?

Git 重写后未执行

git - 在 Git 中将多个提交 merge 为一个

git - 将最新提交拆分为多个分支

git - git pre-commit hook 可以将文件添加到 repo 中吗?

git - 'git remote add' 不创建 repo

git - 如何将 azure 远程分支替换为另一个远程分支 Azure DevOps