11

I'm trying to push commits to a remote and getting this error message:

$  git push origin master
To git@git1.eu1.frbit.com:hbrosuru.git
! [rejected]        ab68c0485d -> master (non-fast-forward)
error: failed to push some refs to 'git@git1.eu1.frbit.com:hbrosuru.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I think I've got in a muddle somewhere by pushing multiple local branches to this single remote branch and I'd like to basically clear out what's on the server and push a whole branch from fresh. Is this possible, or is there a better way to fix this error?

Ps. this remote branch is hosted on Fortrabbit so I've not got full access to the server to simply delete the branch and create a new one because Fortrabbit's deployment mechanism is based on Git.

4

1 回答 1

11

我想基本上清除服务器上的内容并从新推送整个分支。

这很可能意味着强力推动请注意,强制推送通常不是一件安全的事情,在推送到 GitHub 等共享源代码存储库时应特别避免。但在这种情况下,您正在推动更新 PaaS 服务器,这可能没问题。

在强制推送之前,您可能希望使用 、 或其他工具以图形方式可视化您的分支gitkgit log --all --graph --decorate以确保一切看起来都符合您的预期。

要强制将本地master分支推送到origin远程master分支,请运行

git push --force-with-lease origin master:master

--force-with-lease仅当您的本地分支相对于您要推送的分支是最新的时,该参数才会导致强制推送成功。(这可以防止意外覆盖您不知道的提交。)我强烈建议with-lease尽可能使用变体而不是旧--force参数,因为旧参数不太安全。

于 2014-09-08T16:57:04.167 回答