问题:尝试推送(可能长时间运行的)错误修正/维护分支时,出现“由于当前分支的尖端位于其远程对应的后面而导致更新被拒绝”的错误。
设置:开发在master分支上完成。一个提交(在多个提交之后位于主机的HEAD后面)用dev-0.2标签标记。我想基于dev-0.2标签创建一个新的(可能长时间运行的)分支(例如dev-0.2-bugfix),并使用新的dev-0.2-bugfix分支来跟踪与dev-0.2版本相关的更改。 / p>
我做了什么:
$ git checkout -b dev-0.2-bugfix dev-0.2
Switched to a new branch 'dev-0.2-bugfix
$ ..make changes to dev-0.2-bugfix files
$ ..commit changes to local dev-0.2-bugfix branch and now let's try to push it to remote
$ git push origin dev-0.2-bugfix
To file:////var/lib/git/Test.git
! [rejected] dev-0.2-bugfix -> dev-0.2-bugfix (non-fast-forward)
error: failed to push some refs to 'file:////var/lib/git/Test.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 push origin dev-0.2-bugfix:dev-0.2-bugfix
To file:////var/lib/git/Test.git
! [rejected] dev-0.2-bugfix -> dev-0.2-bugfix (non-fast-forward)
error: failed to push some refs to 'file:////var/lib/git/Test.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.
任何想法如何解决这个问题?我希望在远程上创建dev-0.2-bugfix,当前dev-0.2-bugfix不在远程上退出。 我不想带来master的最新更改,因为它们是在dev-0.2标签创建之后提交的,并且不是dev-0.2版本的一部分。
谢谢
更新:尝试强制执行推送,虽然可以正常工作(见下文),但仍未在远程上创建dev-0.2-bugfix:
$ git push -f origin dev-0.2-bugfix:dev-0.2-bugfix
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 2 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 419 bytes | 419.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To file:////var/lib/git/Test.git
+ 337a471...0dd7573 dev-0.2-bugfix -> dev-0.2-bugfix (forced update)
$ git branch -a
* dev-0.2-bugfix
master
remotes/origin/HEAD
remotes/origin/master
答案 0 :(得分:0)
问题是dev-0.2-bugfix
分支是在远程上创建的,但没有显示在git branch -r
或git branch -a
中,这引起了混乱。有关更多信息,请参见Remote branch is not showing up in "git branch -r"。感谢所有回应。