【问题标题】:New commits to github aren't getting accepted.对 github 的新提交没有被接受。
【发布时间】:2015-06-02 13:15:47
【问题描述】:

我编写了一个在线订餐系统,并将代码上传到 github。检查此link
当我尝试从终端进行新提交时,它会返回以下错误。

Username for 'https://github.com': akulkarni9
Password for 'https://akulkarni9@github.com': 
To https://github.com/akulkarni9/miniNet.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/akulkarni9/miniNet.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 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 commit -m "second commit"
git add --all
git push -u origin master
执行这 3 个命令时出现上述错误。我该如何解决?

【问题讨论】:

  • 你需要先做一个git pull
  • 正如错误试图告诉您的那样,您需要拉取远程发生的更改。
  • 我想你的意思是先add,然后commit。否则您的 commit -m 不会提交任何内容。

标签: git github


【解决方案1】:

注意,之前需要添加git commit

由于您有尚未推送的本地提交,最好执行git pull --rebase(以便在更新的origin/master 分支之上重播您的本地提交)

如果git pull 失败,因为本地更改可能被覆盖,您需要存储:

git stash
git pull --rebase
git stash pop

【讨论】:

    【解决方案2】:

    All of the commits on that repository 是一个人,大概是你自己。此处的其他答案考虑了其他人将提交推送到您的存储库的可能性,但情况似乎并非如此。

    如果您自己设法获得了这个,那么您可能使用了git commit --amendgit rebasegit reset 或类似方法来丢弃本地存储库中的旧提交。在这种情况下,您几乎肯定想要将它们从远程存储库中删除,并且命令很简单:只需将 --force 选项添加到 git push

    【讨论】:

      【解决方案3】:

      这是一个常见的问题,即报错:

      git push origin master
      To https://github.com/Joey-project/project.git
       ! [rejected]        master -> master (non-fast-forward)
      error: failed to push some refs to 'https://github.com/Joey-project/project.git'
      

      有人告诉我,发生这种情况的最常见原因是不应该将他/她的分支推送到更新的远程分支。

      我读过一个解决方案是使用类似的东西:

      git fetch origin; git merge origin/master
      

      我不确定,但您是否已经看过此链接For Ruby on Rails project pull request, git push to my fork failing? 它可以提供一些额外的信息。

      干杯。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-18
        • 1970-01-01
        • 2016-06-21
        • 1970-01-01
        • 2021-11-06
        • 1970-01-01
        相关资源
        最近更新 更多