首页 > git rebase遇到的一个疑问

git rebase遇到的一个疑问

最近工作git管理方面遇到一个疑问,如下:
我有两个分支devfeature 分支,目前出现如下疑问,
我在feature分支先执行 git pull origin feature操作,更新本地的分支到最新,然后执行了git rebase dev操作,最后执行git push origin feature时会遇到如下错误

To ssh://xxx@git.xxxx.com/project_xx/xxx.git
 ! [rejected]        feature -> feature (non-fast-forward)
error: failed to push some refs to 'ssh://xxx@git.xxxx.com/project_xx/xxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

最后再执行一次git pull origin feature操作才能成功,这样会产生一条merge log,并且内容为空Showing 0 changed files

疑问,为什么我之前已经执行了pull更新到最新了?不知道是不是我操作流程的问题,请大牛们指教,谢谢!


不好意思,重新测试后发现,和我想得完全不同。
的确会出现reject,只能重新pull再push,而且有可能出现conflict。
[从我自己的实验看,因为rebase后,origin/feature已经出现了分叉,可以使用git gui查看,原因是rebase会改变commit之间的父子关系]

http://stackoverflow.com/questions/8939977/git-push-rejected-after-fea...


问题应该是这样的:
首先,你的feature分支是远端分支,你把他rebase后,本地的feature分支就到了dev分支上了,但是feature的远端追踪分支origin/feature还是在原来的位置上。然后你这样push的话git是不允许的,push的时候git会检查分支的历史commit,当你当前分支的上一个提交不是远端分支上最新的提交时,git就会阻止你提交。要求你pull来跟新分支。
还有就是,让追踪分支和本地分支分离也许不是个很好的做法。如果你的目的是把追踪分支也删除,然后把本地分支的结构同步到远端的话。你可以先把远端的feature删除,git push origin :feature这样本地的追踪分支也就没了。然后你在push就可以了。

【热门文章】
【热门文章】