【问题标题】:Push to repo failed (Git/GitHub)推送到仓库失败(Git/GitHub)
【发布时间】:2016-09-29 18:35:08
【问题描述】:

我正在尝试将我的文件推送到 GitHub 上的存储库,但我收到了错误消息。谁能帮忙解释一下我做错了什么?

正在抛出错误消息,但我无法理解(我是 Git 新手...)

git push -u origin master

> To https://github.com/URL  ! [rejected]        master -> master (fetch
> first) error: failed to push some refs to 'https://URL' hint: Updates
> were rejected because the remote contains work that you do hint: not
> have locally. This is usually caused by another repository pushing
> hint: to the same ref. You may want to first 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.

任何帮助将不胜感激。

【问题讨论】:

    标签: git github push


    【解决方案1】:

    发生这种情况是因为在服务器上您有本地没有的更改。

    关注下方

    1. 远程拉取git pull origin master
    2. 推入遥控器。 git push origin master

    这通常发生在有人在您拉取后推送到远程分支时。因此,您的提交历史记录与服务器提交历史记录不同。在这种情况下,如果 git 允许您推送,服务器上的提交历史记录(事实来源)将被更改,并且从 repo 中提取的人也会面临冲突。因此,您的推送被拒绝。

    但是,如果您非常确定它是一个新的 repo,并且没有人对主遥控器进行任何更改(如下面的 cmets 所述),请运行此 git push -f origin master

    【讨论】:

    • 好吧,这很奇怪,因为这是全新的 repo,所以没有其他人可以从中提取或以任何方式与之交互。我已经设置了具有相同“来源”的其他存储库 - 这可能是问题吗?
    • 不,这应该不是问题。尝试查看git log origin mastergit log master 的输出。第一个用于远程分支,第二个用于本地分支。
    • 我尝试了您的建议,现在我收到了类似的错误消息,包括以下内容:hint: Updates were rejected because the tip of your current branch is behind...
    • 如果你非常确定它是一个新的仓库并且没有人对主遥控器进行任何更改,请运行此git push -f origin master
    • 强制推送。只是不要担心远程上的内容,强制推送我从本地推送的内容。如果对您有帮助,请将我的回答标记为正确:-)
    猜你喜欢
    • 2014-02-16
    • 2014-10-21
    • 2012-09-24
    • 2011-07-26
    • 1970-01-01
    • 2011-02-11
    • 2021-08-22
    • 2013-03-15
    • 1970-01-01
    相关资源
    最近更新 更多