Friday, August 24, 2018

Git Talk 01 - Merge vs rebase

Git is a very useful tool for version control (source control) especially for software developing projects. It helps me a log when I writing the Ansible playbooks for the network automation projects. In this "git talk" series, I would like to introduce some of the interesting topics I have during the studying of Git.

In this 1st post of this series, let's talk about the difference between "git merge" and "git rebase". Generally speaking, both "git merge" and "git rebase" can combine the change from one branch into another. 

"git merge"
When using "git merge xxx" (xxx is the branch which you would like to combine from), git will merge the diff from "xxx" branch to the local branch. If conflict happens, it has to be fixed manually. 

 I will use the following graph as example. In this example, we have two branches, master and feature. These two branches both have commit A and B in the history. Then master has commit C & D. Feature has commit E & F.
 When we merge feature branch to master, the following change will happen. There is a new commit "G" appears in branch master and it combines commit D from master and commit F in feature.
Therefore, we can see the commit history of master branch has not been changed by the "git merge". Just a new commit is added with the combined changes.


"git rebase"

When using "git rebase feature", git will take the commit history of the "feature" branch which is A, B, E, F. Then add its own C and D on top. However, C and D are not the original ones as the new commit C will have the original C plus F. The same, the new commit D will contain the original D plus F. So the master branch commit history will be A, B, E, F, C, D. Although the C and D have different content, their commit time doesn't change. 


No comments:

Post a Comment

NSX Load Balancer "Application Rules" Examples:

Load Balancing is one of the features provided by the NSX Edge Services Gateway (ESG). It can provide L7 Load Balancing by utilizing the HA...