在git rebase之后,我的本地分支和远程分支发生了分歧

Jef*_*eff 5 git git-pull git-rebase

我有一个my-feature分支,被推到原点进行代码审查.它不是共享的.最终它将合并到我的团队中共享的develop分支中.我想将我的分支重新设置为保持历史清洁,然后将我的功能分支合并到develop中.这就是我一直在做的事情:developmy-feature

$ git checkout my-feature
// do some work. make commits.

$ git rebase develop
// fix some conflicts

$ git add .

$ git rebase --continue
Run Code Online (Sandbox Code Playgroud)

成功重新定位后,我检查状态:

$ git status
On branch my-feature
Your branch and 'origin/my-feature' have diverged,
and have 155 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)

$ git what do I do here?
Run Code Online (Sandbox Code Playgroud)

我不知道该怎么做.如果我git pull,那么我注意到我会得到一些没有意义的冲突.有人说强行推,但我很担心.强制将我的主题分支推送到原点是否正常?只要没有其他人使用那个分支?

Von*_*onC 10

首先,你可以git push --force在这个阶段做一个没有任何担心:你说你的分支没有共享.
因此,在服务器端更改其历史记录不会影响任何其他用户.

其次,当你重新分支一个分支时,你用它的远程跟踪分支改变它的共同祖先(origin/xxx)

以前git rebase develop,你有

d--d--d (develop)
    \
     x--x--x--x--x--X--y--y--y (my-feature)
                    |
       (origin/my-feature)   
Run Code Online (Sandbox Code Playgroud)

X是原点/功能和功能之间的共同祖先,这意味着您已在my-feature分支中添加了一些提交.
git状态会返回如下内容:

On branch my-feature
Your branch is ahead of 'origin/my-feature' by 3 commit.
Run Code Online (Sandbox Code Playgroud)

但是当你重新设置那个分支时develop,你会重放开发之上的所有提交my-featureHEAD

        X--X--X--X--X--X--Y--Y--Y  (my-feature)
       /
d--D--d (develop)
    \
     x--x--x--x--x--X
                    |
       (origin/my-feature)   
Run Code Online (Sandbox Code Playgroud)

这一次,共同的祖先my-featureorigin/my-feature不再是几个添加的提交,但完整的历史my-feature,加上一些提交develop!(D这里)

因此地位

Your branch and 'origin/my-feature' have diverged,
and have 155 and 1 different commit each, respectively.
Run Code Online (Sandbox Code Playgroud)

由于您的分支不再共享,因此简单git push --force origin my-feature的操作将完成:

        X--X--X--X--X--X--Y--Y--Y  (my-feature, origin/my-feature)
       /
d--D--d (develop)
Run Code Online (Sandbox Code Playgroud)

(如果my-feature有上游分支,则a git push --force足够,前提是默认推送策略push.default设置为simple.
检查是否git rev-parse --abbrev-ref --symbolic-full-name @{u})