【问题标题】:Failure to push to remote repo in Git无法在 Git 中推送到远程仓库
【发布时间】:2014-12-22 11:44:23
【问题描述】:

我确实提交到本地 repo 并且它工作正常。 但是当我推送到远程仓库时它失败了:

$ git push origin master
Everything up-to-date

Linux 写入“Everything up-to-date”,但在 github 上的远程仓库(使用 SSH 密钥成功插入)中只有 11 天前的东西。 怎么了?

更新

这是提交后的前一个输出 (ci = "commit -a")

$ git ci
[detached HEAD 5b42c77] updated with financial report to calculate for exact contractor and some with table layout for _analogs.php
 12 files changed, 3071 insertions(+), 110 deletions(-)
 rewrite htdocs/protected/controllers/FinancialreportController.php (61%)
$ git push origin master 5b42c77
fatal: 5b42c77 cannot be resolved to branch.
$ git push master 5b42c77
fatal: 'master' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
$ git push origin 5b42c77
fatal: 5b42c77 cannot be resolved to branch.
$ git push 5b42c77
fatal: '5b42c77' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

更新 2

$ git checkout master
M   htdocs/protected/runtime/application.log
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 28 commits.

【问题讨论】:

    标签: git repository push git-remote


    【解决方案1】:

    通过检查git branchgit status 的结果,确保您没有处于detached HEAD 的情况。

    不会推送分离的 HEAD,这将解释“Everything up-to-date”消息。

    如果是,请参阅“How to move master to HEAD?”作为主人:

    git branch -f master HEAD
    git checkout master
    

    或在“How to I “move” my commits from “no branch” to an actual branch?”查看其他建议。

    考虑到您正在明确推送 master (git push origin master),您不需要 git checkout master

    但是,如果您想在 master 之上进行其他提交,那么重要的是您当前的分支是 master(而不是像以前那样直接提交,作为“分离的 HEAD”)。
    因此git checkout master

    【讨论】:

    • 请问如何将 HEAD 附加到我的服务器上的主分支?
    • @IgorSavinkin 首先,你是在本地分离的 HEAD 中吗?
    • 谢谢。我已经听从了你的建议,但这是什么意思:Your branch is ahead of 'origin/master' by 28 commits.这是否意味着在远程回购中仍然是老员工,我需要再次推送?
    • 如果我不想从远程获取旧版本但将当前从本地仓库推送到远程,为什么需要git checkout master
    • 分离的 HEAD 意味着您的 HEAD 当前指向 直接 提交。通常你的 HEAD 应该指向一个分支,该分支又指向一个提交。 git branch -f master HEAD 确保 master 现在正确指向您的最新提交,而 git checkout master 更新 HEAD 以指向 master 而不是直接指向犯罪。所有进一步的提交都将在 master 上进行。
    猜你喜欢
    • 2019-06-29
    • 2014-10-21
    • 2013-02-21
    • 1970-01-01
    • 2015-08-29
    • 2020-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多