简体   繁体   English

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

[英]Trouble pushing changes to remote Git repo

I have started learning Ruby on Rails and Git. 我已经开始学习Ruby on Rails和Git。

Whenever I try to push any changes to my remote repo on Github, I encounter the following error: 每当我尝试对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: I have added all the files in the directory and committed the changes. 注意:我已经在目录中添加了所有文件并提交了更改。 I have not created any separate branches using pull or checkout. 我没有使用pull或checkout创建任何单独的分支。

I am not asking for a solution to the problem. 我不是要解决这个问题。

doing 在做

git push -f or
git push origin +HEAD

worked for me. 为我工作。

What I want to know is, why am I getting the error while trying to push to the original branch. 我想知道的是,为什么在尝试推送到原始分支时出现错误。

follow this and get everything works. 遵循此步骤并确保一切正常。 ... ...

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

Note: this will get your work done and will leave your previous branch. 注意: 这将完成您的工作,并将离开您之前的分支。

or you can try this one also git push heroku +master 或者你也可以尝试这个git push heroku +master

Looks like remote branch is ahead of yours, which means it contains something your local branch does not have. 看起来远程分支位于您的前面,这意味着它包含了本地分支所没有的内容。 You may easily see commits on remote branch since when local branch was created or updated (assuming you run "git fetch origin/master" to fetch remote changes first): 从创建或更新本地分支以来,您可能很容易看到在远程分支上的提交(假设您运行“ git fetch origin / master”首先获取远程更改):

git diff HEAD...origin/master

The output will answer your question why you are getting the error. 输出将回答您的问题,为什么会出现错误。

Now, my guess about the reason of the problem you have is that either someone has access to remote and pushed something, or you modified something using github editing interface and committed since last checkout/pull/merge. 现在,我对出现问题的原因的猜测是,有人可以访问远程并推送了某些内容,或者您​​使用github编辑界面修改了某些内容,并自上次签出/合并/合并以来就提交了。 Using forced push as you did is not a good approach and it messes the history, it basically overwrites the remote branch with your copy, ignoring any remote changes. 像以前那样使用强制推送不是一个好方法,它使历史混乱,它基本上会用您的副本覆盖远程分支,而忽略任何远程更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM