2012-01-17 84 views
3

我目前的分支是my_branch。试图推动修改到远程回购我得到:在为什么“git push”被拒绝? (“git pull”没有帮助)

$ git push 
Counting objects: 544, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (465/465), done. 
Writing objects: 100% (533/533), 2.04 MiB | 1.16 MiB/s, done. 
Total 533 (delta 407), reused 0 (delta 0) 
To [email protected] 
    4ed90a6..52673f3 my_branch -> my_branch 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to '[email protected]' 
To prevent you from losing history, non-fast-forward updates were rejected 
Merge the remote changes (e.g. 'git pull') before pushing again. See the 
'Note about fast-forwards' section of 'git push --help' for details. 

试图git pull结果:

$ git pull 
Already up-to-date. 

为什么我得到这个错误? 我该如何解决此问题并成功执行git push

回答

13

我目前的分支是my_branch。

这就是你的问题。当你拉,Git告诉你,你的分支my_branch是最新的,而不是master,这是origin/master,使快进合并不可能。

为了推高手,你需要检查出master并拉。这将合并等待origin/master的更改并允许您推送自己的更改。

git checkout master 
git pull 
# resolve conflicts, if any 
git push 
+2

如果你只是想推动“my_branch”:混帐推起源my_branch。 – ysdx 2012-01-17 22:24:11

+0

只是为了澄清接受的答案一些:'4ed90a6..52673f3 my_branch - > my_branch'表明'my_branch'已成功更新,但'! [被拒绝]主 - >主(非快进)'表示主分支失败。这意味着* some refs *没有被推送到存储库,但其他一些*可能已经通过了,比如'my_branch'。 – 2012-01-18 01:12:09

1

[如果你的主分支已经配置变基上拉,那么你只需要做的主分支拉在其他answerd描述,但在其他方面:]

如果你得到一个非快速转发的消息,这意味着你只能在现有的提交之上推送提交,但是你正在尝试执行其他操作。做一个变基上主推(假设远程调用原点)前:

git checkout master 
git pull --rebase origin master 
git push 

也看到这个问题:git rebase and git push: non-fast forward, why use?

相关问题