Git for solo developer: merge vs rebase

I am a solo developer and just use Git with private BitBucket repositories. The only thing I do not understand is Merge versus Rebase.

I often switch between desktop and laptop and use BB to access the latest code on any platform. I use rebase when I load the last perfect code, because I think that it essentially clears everything on this platform (desktop or laptop) and ensures that I have an identical code that will be bound to BB. It's right? When should merge be used for such an action?

+5
source share
2 answers

Merge does, as the name suggests, it merges two development branches into one. So, imagine that you have a main branch on the M1 commit. Then you work on your notebook and create the commit N. And also you work on your desktop and create the commit L:

N / M1-L 

When you merge N into L, you merge the changes and get a new commit M2

  N / \ M1-L-M2 

This saves all the changes as they were made, but you get these little double paths that can become quite confusing, especially if you have a lot of them.

Then there is rebase. Starting from the same situation, rebasing takes one of the N or L commits and pretends that it was made after the other. This leads to a new commit n '

 M1-LN' 

N 'and M2 have the same content, just their story looks different.

While you're alone
It does not matter. You will have current status in both directions.

If you are a team
The difference becomes important:

When you rebase branch that someone has already pulled, it can see some confusing effects, because the branch that it was working on suddenly contains completely different commits.
Thus, you do not want to advertise things that have become public.

On the other hand, if you have 10 commit and merge developers, like in hell, the story becomes confusing and you might prefer the developers to work on private repositories and then rebase to push before the integration branch.

+4
source

rebase and merge are different strategies for updating your branch with another branch. rebase changes history so that both branches begin to diverge. merging , on the other hand, does not change the history and can create a new commit to display the merging of the two branches.

See also this relocation vs. merge document . Bottom line: use rebase for your changes to create a neat history; otherwise use merge.

Update: Linus wrote about this in 2009, see his advice on git rebase and merging . Bottom line: relocate only your personal items, with caution. If your commits were pushed, there will be no relocation anymore.

+6
source

Source: https://habr.com/ru/post/1493799/


All Articles