Git commits are duplicated in the same branch after doing a rebase

后端 未结 5 527
夕颜
夕颜 2020-11-29 15:35

I understand the scenario presented in Pro Git about The Perils of Rebasing. The author basically tells you how to avoid duplicated commits:

Do not re

5条回答
  •  臣服心动
    2020-11-29 16:03

    You may have pulled from a remote branch different from your current. For example you may have pulled from Master when your branch is develop tracking develop. Git will dutifully pull in duplicate commits if pulled from a non-tracked branch.

    If this happens, you can do the following:

    git reset --hard HEAD~n
    

    where n ==

    Then make sure you are pulling from the correct branch and then run:

    git pull upstream  --rebase
    

    Pulling with --rebase will ensure you aren't adding extraneous commits which could muddy up the commit history.

    Here is a bit of hand holding for git rebase.

提交回复
热议问题