本地存储库的“git reset --hard HEAD~1”后 Git 推送失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11473150/
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:13:09  来源:igfitidea点击:

Git push failed after 'git reset --hard HEAD~1' of local repo

git

提问by John Dibling

I have a local git repo on my workstation which I push to a dropbox location so that I can pull it down to my laptop via git pull remote dropbox.

我的工作站上有一个本地 git 存储库,我将其推送到保管箱位置,以便我可以通过git pull remote dropbox.

Yesterday I checked in a change on my workstation, committed it and git push dropbox'ed it. I did not do a git pullfrom my laptop because I suspected that I was going to end up throwing that commit away.

昨天我在我的工作站上签入了一个更改,提交并git push dropbox修改了它。我没有用git pull我的笔记本电脑做一个,因为我怀疑我最终会放弃那个提交。

Today I decided to throw that commit away, so on my workstation I did:

今天我决定放弃那个提交,所以在我的工作站上我做了:

git reset --hard HEAD~1

So far, so good. Now I want to push this back up to Dropbox, so that on my laptop I can merge and commit from there. So on my workstation I tried:

到现在为止还挺好。现在我想把它推回 Dropbox,这样我就可以在我的笔记本电脑上从那里合并和提交。所以在我的工作站上我试过:

git push dropbox

And git complained that:

git 抱怨说:

! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '\My Dropbox\dev\repos\xcast.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.

![rejected] master -> master (non-fast-forward) error: failed to push some refs to '\My Dropbox\dev\repos\xcast.git' 为了防止你丢失历史,非快进更新被拒绝在再次推送之前合并远程更改(例如“git pull”)。有关详细信息,请参阅“git push --help”的“关于快进的注意事项”部分。

How do I get my worstation and Dropbox back in sync again?

如何让我的优化和 Dropbox 重新同步?

回答by jli

Force push should work: git push -f dropbox

强制推送应该有效: git push -f dropbox

Git is complaining because your remote still has that extra commit, and thus you are behind it in terms of history.

Git 抱怨是因为你的遥控器仍然有额外的提交,因此你在历史方面落后于它。