Git分支在rebase之后已经发生分歧,那么为什么要rebase? [英] Git branch has diverged after rebase, so why rebase?
问题描述
git checkout -b功能分支
git推送原始功能分支:功能分支
...以及在master中...
git pull原点大师
git checkout feature-branch
git rebase master
但是当我想再次推我的分支时,它说:
在分支功能分支
您的分支和'origin /功能分支'有分歧,
,分别有67个和1个不同的提交。
我在
制作一个 git merge master
进入你的分支是最好在这里:你可以在本地解决冲突,然后你可以进行更多的提交和常规推送。
详情请参阅将 master
合并到分支并合并到 master 中有什么区别? code>?
Recently I came across the notification that my branch has diverged. That was when I made a feature branch, pushed it to remote, and did a rebase with master a few days later when I started working on it again.
git checkout -b feature-branch
git push origin feature-branch:feature-branch
...and when in master...
git pull origin master
git checkout feature-branch
git rebase master
But when I want to push my branch again, it says:
On branch feature-branch
Your branch and 'origin/feature-branch' have diverged,
and have 67 and 1 different commit each, respectively.
I found this answer in "Git branch diverged after rebase":
Since you'd already pushed the branch, you should have merged in the source branch, rather than rebasing against it.
Question
After reading this I still don't fully understand what I should've done differently in my flow, and why I still want to be using git rebase. Hope someone can explain this, thanks!
The idea is to rebase only if you haven't pushed yet, to replay your local commits.
As soon as you have pushed (and are working in a team), you should not rebase the branch on top of master
, as it rewrites its SHA1, forcing you to force push the new state of the branch.
Making a git merge master
into your branch is preferable here: you resolve the conflicts locally, then you can more commits, and a regular push.
See more at "What is the difference between merging master
into branch and merging branch into master
?"
这篇关于Git分支在rebase之后已经发生分歧,那么为什么要rebase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!