最近工作git
管理方面遇到一个疑问,如下:
我有两个分支dev
和 feature
分支,目前出现如下疑问,
我在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
更新到最新了?不知道是不是我操作流程的问题,请大牛们指教,谢谢!
世界只因有你2017-05-02 09:21:29
The question should be like this:
First of all, your feature branch is a remote branch. After you rebase it, the local feature branch will be on the dev branch, but the remote tracking branch of feature, origin/feature, is still at its original location. Then if you push like this, git will not allow it. When pushing, git will check the historical commit of the branch. When the last commit of your current branch is not the latest commit on the remote branch, git will prevent you from submitting. You are required to pull to follow the new branch.
Also, it may not be a good idea to separate tracking branches from local branches. If your purpose is to delete the tracking branch and then synchronize the structure of the local branch to the remote end. You can delete the remote feature first, so that the local tracking branch will be gone. Then you can just push. git push origin :feature
PHP中文网2017-05-02 09:21:29
Sorry, after re-testing, I found that it is completely different from what I thought.
Reject will indeed occur, you can only pull and push again, and conflicts may occur.
[From my own experiments, because after rebase, origin/feature has forked, you can use git gui to view it, because rebase will change the parent-child relationship between commits]
http://stackoverflow.com/questions/8939977/git-push-rejected-after-fea...