![]() ![]() What’s the difference between ‘git merge’ and ‘git rebase’? by VonC.If you know of a great resource you’d like to share or notice a broken link, please let us know. ![]() I’ll try to keep this list current and up to date. Hopefully this article will help you to resolve diverged branches and thank you for reading! Resources Tada! You should have now understand why the diverge would happen, the differences between rebase and merge, how to fix it, and how to make your life easier in the future. Rule of thumb: Frequently rebase your feature branch to make process of resolving conflict easier in the future. However, it might be a pain to resolve conflict while rebasing. I personally like rebase more since it gives more linear git history which would be really helpful when there is a need to look at the git history in the future. Now, to fix it, simply pick the one you think that makes more sense in your case and execute the command and follow the instruction given by the git. When one do merge, this is what will happen,Īs you can see, although your branch and ‘origin/master’ have diverged, it eventually merged together at the end.Īdvantages: Easier and quicker to resolve conflicts. Now, you should have no problem merging your code from your branch to ‘origin/master’.Īdvantages: More clean/linear git history that would help people to find what caused the regression quicker and easier if any.ĭisadvantages: Merge conflict may become more frequent with possibilities of losing your commit history if done wrong. Your branch used to be based off changes B, it is now based off changes D. Let’s explain it in diagram, when one do rebase, this is what will happen, They have their advantages and disadvantages and it really depends on your preferences. There are two ways to fix this problem, one is rebase, another one is merge. Now that we understand the “what”, let’s talk about the “how” here. Note: This typically happens when you are trying to merge your changes to ‘origin/master’ and someone else in your team pushed some other changes after you sync with ‘origin/master’ and before you merge your changes. Your branch started with the changes of E, F and G while the ‘origin/master’ follows the changes of C and D which completely explains the message where it stated “Your branch and ‘origin/master’ have diverged, and have 3 and 2 different commits each, respectively.” Here, the 3 represent the E, F, and G while the 2 represent the C and D. Starting from changes B, your branch and ‘origin/master’ started to diverged. I have drawn the diagram to show you what happened, here is the picture,Īs you can see, up until the changes B, your branch and ‘origin/master’ is exactly the same. Before we talk about how to fix it, we should talk about how this can happen to you. You are in luck, in this tutorial, we are going to talk about how this happen, how to fix it and how to avoid this from happening in the future. Ever try to commit and push your changes to master branch and see this annoying message stated that your branch and ‘origin/master’ branch have diverged, ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |