Eclipse 上的 EGit:如何 git push --force?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12302171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:27:50  来源:igfitidea点击:

EGit on Eclipse: How to git push --force?

gitegit

提问by Jason

I've run into a problem with my origin/branch being out of sync with my local branch, see below

我遇到了一个问题,我的源/分支与我的本地分支不同步,见下文

My commit history

我的提交历史

When I try to PUSH from my local "staging" branch to the origin/staging branch I get the "rejected - non-fast-forward" error.

当我尝试从本地“暂存”分支推送到源/暂存分支时,我收到“拒绝 - 非快进”错误。

I use Eclipse with the EGit module on a windows PC.

我在 Windows PC 上使用带有 EGit 模块的 Eclipse。

From another post hereI see that I can resolve my issue with the "git push --force origin staging" to over-ride the origin/staging branch with my local branch.

这里的另一篇文章中,我看到我可以通过“git push --force origin staging”解决我的问题,用我的本地分支覆盖 origin/staging 分支。

However, I don't see that option with EGit, and I don't see how to open a console in EGit to do this?

但是,我在 EGit 中看不到该选项,也看不到如何在 EGit 中打开控制台来执行此操作?

Does anyone know if I can do this within EGit?

有谁知道我是否可以在 EGit 中做到这一点?

OK - fixed my own issue. It appears I had issues with Commits that had not been Pushed back to origin/staging. Found an overview hereon using the "git reset XXX : without --hard" which resets the branch marker, but keeps the local changes for later recommits.

好的 - 修复了我自己的问题。看来我在提交方面遇到了问题,这些问题尚未被推回原点/暂存。在这里找到关于使用“git reset XXX : without --hard”的概述,它重置了分支标记,但保留了本地更改以供以后重新提交。

Thanks, Jason

谢谢,杰森

回答by Tomek Samcik

I have just come across a similar issue and here's what I did:

我刚刚遇到了类似的问题,这就是我所做的:

  1. Team -> Push Branch <name of branch> ...
  2. Force overwrite of branch on remote if it exists and has diverged
  1. 团队 -> 推送分支 <分支名称> ...
  2. 如果远程分支存在并且已经发散,则强制覆盖远程分支

回答by chrisbunney

Are you sure you want to overwrite the remote branch and lose all those commits?

您确定要覆盖远程分支并丢失所有这些提交吗?

If there are commits on the remote branch that aren't in your local branch, you should merge them into your local branch before pushing

如果远程分支上存在不在本地分支中的提交,则应在推送之前将它们合并到本地分支中

For example, whilst on your local stagingbranch:

例如,在您当地的staging分支机构中:

git merge origin/staging

However, if you're sure, then I suggest you check the "Force update" option on the push refspec.

但是,如果您确定,那么我建议您检查 push refspec 上的“强制更新”选项。

It's a little complicated to get to, but the EGit user guide explains it when discussing Pushing to other Repositories, and the specific section that mentioned the "Force Update" option is in the section on Push Ref Specifications

上手有点复杂,但是 EGit 用户指南在讨论Pushing to other Repositories时对此进行了解释,提到“强制更新”选项的具体部分在Push Ref Specifications 部分

Edit 0:With respect to your failed merge, I've not yet encountered a merge that fails outright rather than result in a conflict, and it appears it may be a known issue

编辑 0:关于你失败的合并,我还没有遇到过完全失败而不是导致冲突的合并,它似乎是一个已知问题

回答by Karl Bielefeldt

If you do a force push, you will lose everything added to origin/stagingafter fixing the missing Location: string in the header, and you'll break everyone else's branches. I don't think that's what you want. You probably want to do a pull first, then the push will work just fine.

如果您进行强制推送,origin/staging在修复标题中缺少的 Location: 字符串后,您将丢失添加的所有内容,并且您将破坏其他所有人的分支。我不认为那是你想要的。你可能想先做一个拉,然后推就可以了。