Hacker News new | past | comments | ask | show | jobs | submit login

> The decision of when to merge vs. rebase is still confusing to me.

I'll take a stab at this. When you merge, you're merging their branch into yours. At the end of you have both pieces of code, but all the history is still there. You can see that their branch started 20 commits ago, that two things were done in parallel, and that they came back together with the merge.

Rebase is a different. Rebase changes history. Rebase is like this:

    1. Find the common ancestor between the branches
    2. Extract each commit from their branch, turn it into a patch (named patch*N*)
    3. Switch back to your branch
    4. Apply patch1, patch2, ... patch*N* in order
Now it looks like all the work was done at the end of your brach, like it was based on your latest commit. Instead of being based on the common ancestor commit, it is now based on your commit. It's been rebased.

It makes sense if you think about Git coming from kernel development. Developers tended to work in patch sets, a long series of patches to a common base. Rebaseing is just applying that series of patches to a different base.

Merging merges branches, but rebase is more like moving branches.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: