First of all, based on my experience, if your scenario is the team(multi people) is developing the branches at the same time. Then Rebase
will not suitable for that. Because if one of your colleague execute the rebase
, it can modify all commits. Meanwhile, if another person is developing this branch, it is very likely that the public parent node could not be found, and the commit could not be submitted.
rebase
can make the history more clear(one line), but merge
not.
Rebasing vs Pull request vs Merge
Pull request just used to raise a request to decide the way on how to "solve" commits between branches. After the pull request raised, you can decide the strategy on which merge type you would choose.
For better explain the Rebase and Merge, here I set the scenario first:
Assuming that you have two branches, master and develop. develop is the branch that is pulled from the master at (3.added merge.txt file)commit:

And now, set HEAD is at 6.added hello.txt file, which is the most recent commit of the master branch.
Based on the above scenario, execute git merge develop
. Below is the result shown:

The Git will do a Three-way merge automatically by following the common ancestor of the two branches (3.added merge.txt file), the latest commits of the two branches (6.added hello.txt file)
and (5.added test.txt file)
. Then a new commit will generated based from the modified content in the merge, that is, commit 7. Merge branch 'develop'.
This is the effect of the merge
, which simply merges the two branches and generates a new commit.
Also, based on the above scenario, execute git rebase develop
. Below is the result shown:

You can see that the develop branch and the fork are disappeared.
When performing a rebase
operation, git will extract the changes(6.added hello.txt file)
from the current branch(master)
, and this changes is start from the common ancestor of the two branches(3.added merge.txt file)
.
Then let the master branch points to the latest commit(5.added test.txt file)
of the target branch develop . And apply the changes which extracted just now to this latest commit.
If there are multiple changes to the extraction, then git will be applied to the latest commit in turn. As shown in the following, left is the initial state, and right is the state after the implementation of rebase:

In one word, the git rebase
extraction operation is a bit like git cherry-pick
(just similar, but not same). After rebase
executed, it will cherry-pick the current commit sequentially, and then sent to the target branch. After that, the extracted commit on the original branch is deleted.
Summary:
You can see that the result of the merge
can reflect the timeline, but rebase
will disrupt the timeline. Both of them can all achieve code combined, just for public branch, like master, do not suggest use Rebase
.
Also, the trouble for merge is roll back commit node. But for rebase is after rebase is finished, you will not know where you pulled out the development branch, this is what I mentioned disrupt the history timeline.