git rebase implementation details

六月ゝ 毕业季﹏ 提交于 2019-12-06 06:26:15

Your summary is basically complete. Rebase is actually relatively simple.

  1. First, the work to do is calculated. This is basically git rev-list <upstream>..<branch> to identify all the commits that need to be moved over.
    1. If you are doing a normal (patch-based) rebase, then the patches for each of those commits will be generated and saved in the rebase state folder (.git/rebase-apply).
    2. If you invoked rebase with git rebase --merge then the commits are stored in a different state folder (.git/rebase-merge).
  2. Next, the HEAD is detached and set to the onto commit (the new base branch, where you will be applying those changes).
  3. Application takes place until a commit cannot be applied.
    1. If you are doing a patch-based rebase, then patches are applied in order. If a patch fails to apply, then Git will try to instead cherry-pick the commit in question. This is because cherry-pick is able to write merge conflicts to the index and working directory.
    2. If you are doing a merge-based rebase, then the commit is cherry-picked.
  4. If a cherry-pick fails with conflicts, rebase stops and you (the user) must resolve any conflicts and git add them to the index. When you have resolved all conflicts, you can git rebase --continue.
  5. Once all conflicts have been applied, the original branch is updated to point to the final, rebased commit.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!