Home git What is the difference between Git Rebase and Git Merge?

What is the difference between Git Rebase and Git Merge?

Author

Date

Category

Tell me, please, what is the essential difference between Merge and Rebase. I read the answer on this link And the only thing that understood is what rebase can change (changes the commit), and Merge creates a new one, so when viewing history, more reliable information will be if you run Git Merge. Then why there is such a team as Git Rebase. Also, at referenceting Rebase, the linearity of history is always mentioned, so what happens when Merge?


Answer 1, Authority 100%

Merge creates merge commit. And after Merge there are three convenient commit. To continue using only the first thread, only the second thread, or all together.

Commit A - & GT;
      | - & gt; Merge Commit C.
Commit B - & GT;

In essence, Merge creates a story.

and rebase changes its story. Suppose you wrote your work D Using only the visible branch Commit A .

& gt; Job D.
    /
Commit A - & GT;
      | - & gt; Merge Commit C.
Commit B - & GT;

But changed his mind and moved all their work in the branch of the Commit B . And made rebase on Commit B:

Commit A - & GT;
      | - & gt; Merge Commit C.
Commit B - & GT;
    \
     & gt; Job D.

or after Rebase on Commit with:

Commit A - & GT;
      | - & gt; MERGE Commit C - & GT; Job D.
Commit B - & GT;

rebase use if they want to continue the work based on someone’s work of another person. All Commitments of your branch Work D These are new commitments, everything is rewriting in a new one and everything is forgotten.

Linearity This is what your operation D uses everything that can be seen (A, B, C). If you use merge Instead of Rebase , this graph will be obtained:

& gt; D - & GT work; \
    / | - & gt; Merge D & amp; C.
Commit A - & GT; /
      | - & gt; MERGE Commit C - & GT;
Commit B - & GT;

And there is an opportunity to continue your branch as without merger and with him. Rebase has a destructive action for history. If you change your mind to use the Commit C, then it will come again to do rebase .


ANSWER 2, AUTHORITY 11%

rebase is needed for order (linearity of the story), so that then look and understand.
Rebase transfers commits on top of what was in the resulting branch.
Merge leaves commits as it is, simply adding a binding commit between branches.

Here the whole book:
https://git-scm.com/book/en/v2

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions