Rebase using egit

徘徊边缘 提交于 2019-12-11 08:35:40

问题


I'm on a feature branch, and I've just done a succesful rebase (Team > rebase > master) so my branch doesnt get too far from master.

Now in the Eclipse git history, I can see the 5 commits of my branch are on top of master, which is the expected result.

But there are some indicators next to the project name, saying [up-arrow] 7 [down-arrow] 5, and when I try to push my branch on the remote branch, it says : "rejected non-fast-forward" (I'm working alone on this remote repository and I have only one git client which is Eclipse egit).

Could someone tell me how I can be "non-fast-forward" after a rebase ? And what should I do from now ? "rebase" again ? "pull" ? "merge" ?


回答1:


It is not fast forward because your updated branch can no longer be reached by moving forward starting with where it was originally (which is where the remote still is). Git commits are immutable, so an entirely new set of commits is made when you rebase, containing the same change sets your original ones did:

      master & origin/master  feature
                |                |
                v                v
 M -- N -- O -- P -- A' -- B' -- C'
       \
        A -- B -- C
                  ^
                  |
            origin/feature

This diagram should explain pretty clearly why you can't get from origin/feature to feature through a fast forward.

You can solve this in two ways. If you have the permissions set up, you can do a force-push. This is the easiest standard way to handle the situation. On egit, you do

  1. Team -> Push Branch
  2. Select "Force overwrite..."

(from EGit on Eclipse: How to git push --force?)

Another alternative would be to merge master into your branch instead of doing a rebase. This is not as clean history-wise, but it would replace your copied commits with a single merge commit, fixing your fast forwarding problem. The graph would look like this:

      master & origin/master
                |
                v
 M -- N -- O -- P --
       \             \
        A -- B -- C -- D
                  ^    ^
                  |    |
                  | feature
            origin/feature

As you can see, feature will be at a merge commit that is fast-forwardable from origin/feature.

An even more complicated way would be to go on the server, reset feature to master, and then push from the client again. This is not a good idea in general, but it would guarantee that the push would be fast-forward:

 # On the server:
 git checkout feature
 git reset --hard master


来源:https://stackoverflow.com/questions/51270665/rebase-using-egit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!