【问题标题】:Pushing to Github on Mac returns error everytime在 Mac 上推送到 Github 每次都会返回错误
【发布时间】:2019-05-12 00:52:02
【问题描述】:

每次我尝试推送到 Github 时都会收到一条错误消息:

Dominics-Air:django dominic.$ git push -u origin master

To https://github.com/domtom1126/django.git

 ! [rejected]      master ->  master (fetch first)

error:  failed to push some refs to 'https://github.com/gomtom1126/django.git'
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 tot first integrate the remote changes
hint: (g.h., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Dominics-Air:django dominic.$

我尝试在不同的路径上安装 git,但没有任何效果。我正在使用运行 Mojave 的 MacBook Air。

【问题讨论】:

标签: git


【解决方案1】:

所以事实证明,如果你已经在本地提交了 git,你不应该通过 Github 使用 README.md 进行初始化,而是通过 git 自己创建一个。据说如果有一个现有的本地存储库,你不应该编写自述文件,但由于我没有阅读这是会出现的错误。

【讨论】:

    【解决方案2】:

    运行:

    >git fetch origin
    >git rebase origin/master
    >git push origin master
    

    这里,第一步是从Remote获取代码。

    第二步是rebase你的代码与远程的主分支。在这一步你可能会遇到conflicts,你需要解决它们。

    第三,push 到 master 分支。

    【讨论】:

    • 如果你在变基,为什么要强制推送?它增加了不必要的风险,不应使用。
    • 好吧,就像history changes rebase 之后,当你尝试推送到远程时,它会拒绝它,因为本地和远程之间的历史不匹配。这就是为什么你需要强制推动
    • “好吧,因为历史在变基后会发生变化”,前提是它不是快进。对于公共/共享分支,我会不惜一切代价避免强制推送。
    • @ruddra 强制推送只是因为变基才需要,这与合并提交或快进不同。
    • 是的,你是对的。我的坏(我把它和快进混在一起了)。更新了答案。
    猜你喜欢
    • 1970-01-01
    • 2022-01-26
    • 2016-11-24
    • 1970-01-01
    • 2023-04-10
    • 2013-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多