对github的新提交不被接受。

时间:2015-03-29 15:00:26

标签: git github

我写了一个在线食品订购系统,我已将代码上传到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个命令时,我得到上述错误。我该如何解决?

3 个答案:

答案 0 :(得分:2)

请注意,您需要在 git commit之前添加

由于你还有尚未推送的本地提交,最好做一个git pull --rebase(为了在更新的origin/master分支上重放你的本地提交)

如果git pull失败,因为可能会覆盖本地更改,则需要隐藏:

git stash
git pull --rebase
git stash pop

答案 1 :(得分:2)

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

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

答案 2 :(得分:1)

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

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? 它可以提供一些额外的信息。

干杯。