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

当我使用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.

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


当前回答

我创建了一个自定义预推送文件,我忘记以exit 0结束它。

这导致我得到这个“未能推动一些裁判”错误。我将exit 0添加到pre-push hook的末尾,当然,现在它工作得很好。

其他回答

对我来说,我忘记在点击推送之前添加和提交。

So:

git add --all
git commit -m "First commit."

然后按一下,就可以了:)

对我来说,问题是我没有在提交之前添加文件。

转到添加 。

Git commit -m "your msg"

在我的例子中,这两行就解决了问题。

git add .
git commit -m "Changes"

实际上,我忘记添加并提交我的更改,只是第一次尝试推送它。

git init
git remote add origin https://github.com/anything/repo-name.git
git add .
git commit -m "Changes"
git branch -M main
git push -u origin main

希望这能有所帮助!

当您没有任何文件时,可能会发生这种情况。 尝试创建一个文本文件,然后执行以下命令:

git add .
git commit -m "first commit"
git push --set-upstream origin master

Try:

git push -f origin master

这样问题就解决了。

根据@Mehdi的评论,关于-force push有一个澄清:上面的Git命令只在第一次提交时安全工作。如果之前已经有提交,拉请求或分支,这将重置所有它,并将其从零设置。如果是这样,请参考@VonC的详细回答,以获得更好的解决方案。