Answering your questions.
1 - After rebase in the master branch, the history will be
following way?
Yes
2 - If yes, what is the purpose of redoing the history
when one of the advantages of GIT is to be able to see the history as it
is?
The problem with rebase
is that it changes history, as well as other git commands (such as those with the --hard
attribute). This is why it is recommended only in very specific cases . Git does not have the premise of protecting the change history at any cost but by default preserving it.
Here's what happened in each% of% you did.
Remembering that commit
is where your repository is currently pointing (can be HEAD
, branch
or tag
specific).
Understanding the step-by-step scenario
Next, I'll detail what happened in each step you described to commit
.
Come on:
Branch master with 3 commits (A, B and C).
A<---B<---C
|
|
|Master|
|
HEAD
Command:
git checkout master
After commit C, I created a new branch named design.
HEAD
|
|design|
|
|
A<---B<---C
|
|
|Master|
Command:
git commit -m "Commit C"
git checkout -b design # cria a branch design a partir da branch atual (master)
I made a commit (D) in branch design
HEAD
|
|design|
|
|
.---D
/
A<---B<---C<--´
|
|
|Master|
Command:
git checkout design
git commit -m "Commit D"
and returned to the master branch.
|design|
|
|
.---D
/
A<---B<---C<--´
|
|
|Master|
|
HEAD
Command:
git checkout master
I made a commit (E) in the master branch.
|design|
|
|
.---D
/
A<---B<---C<--´-----E
|
|
|Master|
|
HEAD
Command:
git commit -m "Commit E"
And doing rebase
:
|design|
|
|
.---D<----E'
/ |
A<---B<---C<--´ |
|Master|
Command:
git checkout design
git rebase master
As you can see, with the rebase
of the master in the rebase
branch, the design
commits go to the top of the E
branch.
So, as you may notice in the end, the commits were as you said:
- master: A, B, C, D, E
- design: A, B, C, D