By answering your questions.
1 - After rebasing on the master branch, the history will be
as follows?
Yes
2 - If the answer is yes, what is the purpose of redoing the history
when one of the advantages of GIT is being able to view the history just like it
is?
The problem of rebase
is that it changes the history as well as other git commands (such as those that carry the attribute --hard
). This is why it is recommended only in very specific cases. Git does not have the premise of protecting the history of changes at any cost, but of preserving this by default.
See below what happened in each commit
who made.
Remembering that HEAD
is where your repository is currently pointing to (could be a branch
, tag
or commit
specific).
Understanding the step-by-step scenario
Next, I will detail what occurred in each step you described until the rebase
.
Come on:
Branch master with 3 commits (A, B and C).
A<---B<---C
|
|
|Master|
|
HEAD
Commando:
git checkout master
After committing C, I created a new branch with the name design.
HEAD
|
|design|
|
|
A<---B<---C
|
|
|Master|
Commando:
git commit -m "Commit C"
git checkout -b design # cria a branch design a partir da branch atual (master)
I committed (D) to branch design
HEAD
|
|design|
|
|
.---D
/
A<---B<---C<--´
|
|
|Master|
Commando:
git checkout design
git commit -m "Commit D"
and went back to the master branch.
|design|
|
|
.---D
/
A<---B<---C<--´
|
|
|Master|
|
HEAD
Commando:
git checkout master
I committed (E) to the master branch.
|design|
|
|
.---D
/
A<---B<---C<--´-----E
|
|
|Master|
|
HEAD
Commando:
git commit -m "Commit E"
And making the rebase
:
|design|
|
|
.---D<----E'
/ |
A<---B<---C<--´ |
|Master|
Commando:
git checkout design
git rebase master
As you can see, with the rebase
from master on branch design
, the more commits (E
) of master
go to the top of the branch design
.
So, as you can see at the end, the commits turned out like you said:
- master: A, B, C, D, E
- design: A, B, C, D
rebase is usually useful when only you touch a particular project, but when you don’t want to waste time merging, it overwrites the history with updates and ignores conflicts, keeping its update as the latest and also despises changes in the middle of the project made by other people.
– Ivan Ferrer