无法将更改推送到远程Git仓库

时间:2013-10-14 11:45:52

标签: ruby-on-rails git github

我已经开始学习Ruby on Rails和Git。

每当我尝试将任何更改推送到Github上的远程仓库时,我都会遇到以下错误:

C:\Sites\first>git push origin master
To git@github.com:piy9/Twitter_clone.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:piy9/Twitter_clone.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

NOte:我已添加目录中的所有文件并提交了更改。我没有使用pull或checkout创建任何单独的分支。

我不是要求解决这个问题。

git push -f or
git push origin +HEAD

为我工作。

我想知道的是,为什么我在尝试推送到原始分支时遇到错误。

2 个答案:

答案 0 :(得分:0)

按照此操作,让一切正常。 ...

git branch production
git checkout production
#do some code changes
git commit -am "some desparate code changes to try fix heroku"
git push heroku production:master

注意:这将完成您的工作,并将离开您之前的分支。

或者你也可以尝试这个git push heroku +master

答案 1 :(得分:0)

看起来远程分支在您的前面,这意味着它包含您的本地分支没有的东西。您可以在创建或更新本地分支时轻松查看远程分支上的提交(假设您运行“git fetch origin / master”以首先获取远程更改):

git diff HEAD...origin/master

输出将回答您的问题,为什么会收到错误。

现在,我对你遇到的问题的原因的猜测是,有人可以访问远程和推送的东西,或者你使用github编辑界面修改了一些东西,并且自上次checkout / pull / merge以来已经提交了。像你一样使用强制推送不是一个好方法,它会混淆历史,它基本上用你的副本覆盖远程分支,忽略任何远程更改。

相关问题