When do you use Git rebase instead of Git merge?

后端 未结 17 2652
独厮守ぢ
独厮守ぢ 2020-11-21 11:25

When is it recommended to use Git rebase vs. Git merge?

Do I still need to merge after a successful rebase?

17条回答
  •  遥遥无期
    2020-11-21 12:10

    The Pro Git book has a really good explanation on the rebasing page.

    Basically a merge will take two commits and combine them.

    A rebase will go to the common ancestor on the two and incrementally apply the changes on top of each other. This makes for a 'cleaner' and more linear history.

    But when you rebase, you abandon previous commits and create new ones. So you should never rebase a repository that is public. The other people working on the repository will hate you.

    For that reason alone I almost exclusively merge. 99% of the time my branches don’t differ that much, so if there are conflicts it's only in one or two places.

提交回复
热议问题