我有我的本地开发分支(本地/ dev),原始存储库(origin / master)的主分支和我的远程dev分支(remote / dev)。启动时,本地/ dev和远程/ dev同步。
现在我想从origin / master获取更改,使用我的本地/ dev重新绑定它并将其推送到远程/ dev。
所以我在我的本地/ dev存储库中执行了git pull --rebase origin master
,这似乎工作正常。
但git status
让我回答:
On branch dev
Your branch and 'remote/dev' have diverged,
and have 8 and 5 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
和git push remote dev
将导致
To github.com:PascalTurbo/dev.git
! [rejected] logger -> logger (non-fast-forward)
error: failed to push some refs to 'git@github.com:PascalTurbo/dev.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.
我该如何解决这个问题?
答案 0 :(得分:1)
实际上执行git pull --rebase origin master
时效果不佳。让我们通过下面的图表来说明(有两个存储库 - 本地和原点,这也用于三个存储库):
A---B---C local/dev, origin/dev
/
D---E---F---G origin/master
git pull --rebase origin master
之后
A---B---C origin/dev
/
D---E---F---G---A’---B’---C’ local/dev
|
origin/master
所以它真的是本地/开发和远程/ dev的分歧,并不是你真的想要它。 有一种方法可以让您实现自己的要求:
git fetch remote
git reset --hard remote/dev
git pull origin
git checkout master
git rebase dev
git checkout dev
git merge master
git branch –D master
git checkout dev
git push remote dev