Egit rejected non-fast-forward

前端 未结 9 1813
夕颜
夕颜 2020-12-07 07:28

I am getting this message while pushing to github repository. Can you tell me step by step procedure to fix it? I pushed only once and it was successful. But, when I updat

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 08:04

    Applicable for Eclipse Luna + Eclipse Git 3.6.1

    I,

    1. cloned git repository
    2. made some changes in source code
    3. staged changes from Git Staging View
    4. finally, commit and Push!

    And I faced this issue with EGit and here is how I fixed it..

    Yes, someone committed the changes before I commit my changes. So the changes are rejected. After this error, the changes gets actually committed to local repository. I did not want to just Pull the changes because I wanted to maintain linear history as pointed out in - In what cases could `git pull` be harmful?

    So, I executed following steps

    1. from Git Repository perspective, right click on the concerned Git
      project
    2. select Fetch from Upstream - it fetches remote updates (refs and objects) but no updates are made locally. for more info refer What is the difference between 'git pull' and 'git fetch'?
    3. select Rebase... - this open a popup, click on Preserve merges during rebase see why
      What exactly does git's "rebase --preserve-merges" do (and why?)
    4. click on Rebase button
    5. if there is/are a conflict(s), go to step 6 else step 11
    6. a Rebase Result popup would appear, just click on OK
    7. file comparator would open up, you need to modify left side file.
    8. once you are done with merging changes correctly, goto Git Staging view
    9. stage the changes. i.e. add to index
    10. on the same view, click on Rebase-> Continue. repeat 7 to 10 until all conflicts are resolved.
    11. from History view, select your commit row and select Push Commit
    12. select Rebase Commits of local....... checkbox and click next. refer why - Git: rebase onto development branch from upstream
    13. click on Finish

    Note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.

提交回复
热议问题