问题在于,如果我在合并时遇到冲突,在合并完成后我无法推送到我的远程开发者分支(在Github上),直到我拉取我的远程分支。这会导致重复提交。当没有冲突时,工作正常。
问题是:在重新设置基础和解决冲突后,如何同步本地和远程开发者分支,而不创建重复提交?
设置:
// master branch is the main branch
git checkout master
git checkout -b myNewFeature
// I will work on this at work and at home
git push origin myNewFeature
// work work work on myNewFeature
// master branch has been updated and will conflict with myNewFeature
git pull --rebase origin master
// we have conflicts
// solve conflict
git rebase --continue
//repeat until rebase is complete
git push origin myNewFeature
//ERROR
error: failed to push some refs to 'git@github.com:ariklevy/dropLocker.git'
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.
// do what git says and pull
git pull origin myNewFeature
git push origin myNewFeature
// Now I have duplicate commits on the remote branch myNewFeature
编辑
看起来这会破坏工作流程:
developer1 正在开发 myNewFeature developer2 正在开发 hisNewFeature 两者都使用主分支 master
developer2 将 myNewFeature 合并到 hisNewFeature 中
developer1 变基,解决冲突,然后强制推送到 myNewFeature 的远程分支
几天后,developer2 再次将 myNewFeature 合并到 hisNewFeature 中
这会让其他开发人员讨厌 developer1 吗?
rebase
。为什么不直接使用git pull
和git merge
呢? - AdamT