在github
上推送一些提交给我的分叉回购的问题查看当前状态
$ git remote -v
origin git@github.com:claudio4j/hal-core (fetch)
origin git@github.com:claudio4j/hal-core (push)
upstream git://github.com/hal/core.git (fetch)
upstream git://github.com/hal/core.git (push)
$ git branch -v
* gui_enhancements c1adba1 remove backup pom.xml~ file
master 5128b4d HAL-335: Workaround using include-aliases=true; more fail-safe RBACGatekeeper
$ git status
# On branch gui_enhancements
nothing to commit, working directory clean
$ git pull --rebase upstream master
From git://github.com/hal/core
* branch master -> FETCH_HEAD
Current branch gui_enhancements is up to date.
推送失败。
$ git push origin gui_enhancements
To git@github.com:claudio4j/hal-core
! [rejected] gui_enhancements -> gui_enhancements (non-fast-forward)
error: failed to push some refs to 'git@github.com:claudio4j/hal-core'
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.
看起来我的分叉回购与上游相比没有更新 fork:https://github.com/claudio4j/hal-core/commits/gui_enhancements 上游:https://github.com/hal/core/commits/master
“git pull”没有更新我的分叉回购吗?
这是我无法推动的原因吗?
感谢您的帮助。
克劳迪奥
答案 0 :(得分:1)
git pull --rebase
执行fetch
后跟rebase
。 Rebasing在新主服务器上重放提交,因此它“改变了历史记录”;在gui_enhancements
的尖端的旧提交不是新提交的祖先。
如果您是唯一一个在您的分支上使用此分支的人,可能就是这种情况,您需要做的就是:
git push -f origin gui_enhancements
-f
将迫使推进。
如果其他人在你的分支上与你合作,那么重写历史会让事情变得尴尬而你应该使用真正的(非rebase
)拉动。以这种方式重做:
# I'm taking the sha that your branch used to be on from the output you pasted.
git reset --hard c1adba1
# No --rebase option.
git pull upstream master
# Since "git pull" did a merge commit this time, it'll be a descendant of the
# old gui_enhancements ref on origin, and the push should succeed.
git push