我昨天还能推,现在却推不动了。

当我使用git push origin master时,我得到一个错误:

$ git remote -v
origin  https://github.com/REDACTED.git (fetch)
origin  https://github.com/REDACTED.git (push)

$ git push origin master
Username for 'https://github.com': REDACTED
Password for 'https://REDACTED@github.com':
To https://github.com/REDACTED.git
! [rejected]         master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/REDACTED.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我的工作目录和远程存储库看起来像什么:


当前回答

就我而言,我错过了修改。我只需要运行git commit -amend,然后push。它解决了这个问题。它可能会帮助以前提交过代码的人。

其他回答

在我的例子中,分支名称前缀已经存在于远程,所以基本上,如果你有一个分支名称“fix”,你不能推送另一个名称为“fix/new_branch_name”的分支。

重命名分支解决了我的问题。

在我的案例中,问题是(奇怪的是)没有一个叫做master的分支。我从GitHub获取了这个存储库。

对于Sourcetree用户

首先进行初始提交,或者确保没有任何未提交的更改。然后在Sourcetree的一侧有一个“REMOTES”。右键单击它,然后单击“推到原点”。好了。

在我的案例中,Git预推钩子有一个问题。

运行git push——verbose查看是否有任何错误。

在. Git /hooks目录下仔细检查你的Git钩子,或者将它们临时移动到另一个地方,看看之后是否一切正常。

在Azure DevOps中使用Git存储库时,问题在于分支策略要求所有对分支的更改必须通过pull request (PR)进行。尝试直接将更改推到分支生成错误“failed to push some refs to…”

我创建了一个公关部门,毫无问题地进行推广。