git pull --rebase lost commits after coworker's git push --force

后端 未结 4 723
情话喂你
情话喂你 2020-12-01 19:47

I thought I understood how git pull --rebase was working, but this example is confusing me. I would have guessed that the following two scenarios would produce identical res

4条回答
  •  青春惊慌失措
    2020-12-01 20:19

    Both the scenarios are not confusing, that's how push --force works.

    I will not explain the first scenario because you also understand that. But in the second scenario when brian$ git push --force this happens, brian's local repository doesn't know anything about dan's push to the remote.

    So it take brian's local copy & replace everything there in the remote because it's a force push.

    The difference between git pull & git pull --rebase is,

    git pull will compare the changes of origin & local. That's why even you have uncommited changes you can git pull.

    git pull --rebase will not compare the changes with the local, but it takes everything from the origin. That's why you can't git pull --rebase if there are uncommited changes

    Hope you understand what I said. Any questions??

提交回复
热议问题