{"id":5688,"date":"2021-01-19T12:34:25","date_gmt":"2021-01-19T13:04:25","guid":{"rendered":"https:\/\/ultering.com\/it4us\/?p=5688"},"modified":"2023-08-02T03:28:42","modified_gmt":"2023-08-02T03:58:42","slug":"git-rebase-when-and-where-not-to-do","status":"publish","type":"post","link":"https:\/\/ultering.com\/it4us\/?p=5688","title":{"rendered":"Git: Rebase &#8211; When and Where Not To Do"},"content":{"rendered":"<p>There are many good posts about the differences between pulling with and without rebase, merge and etc.<br>\nIf you desire to refresh memory about this, try these:<\/p>\n<p><a href=\"https:\/\/ultering.com\/itstuff\/?p=3393\">git: the difference between git pull and git pull \u2013rebase<\/a><\/p>\n<p id=\"d175\" class=\"fo fp fq fr b fs ft fu fv fw fx fy fz ga gb gc gd ge gf gg gh gi gj gk gl gm cg\"><a href=\"https:\/\/medium.com\/nerd-for-tech\/git-branching-and-merge-vs-rebase-9fc2d736c93\">Git Branching and Merge vs Rebase-&nbsp;<\/a><\/p>\n<div class=\"article-grid-head\">\n<div class=\"d-flex flex-items-baseline flex-justify-between mt-3\">\n<h3><\/h3>\n<h3 class=\"border-bottom-0\">This post intends to supply information on when and where not to do a rebase.<br>\nThrough an example of our typical day life when things go wrong and the documentation let interrogation marks on your mind: and what does it happen then?<\/h3>\n<p><strong><br>\nScenario<\/strong><\/p>\n<\/div>\n<p>Suppose that the master branch is very difficult to understand, having so many threads tangled among them that you start thinking about if &#8220;rebasing&#8221; wouldn&#8217;t help.<br>\nPlease, for the sake of your own happiness and dignity, don&#8217;t.<\/p>\n<p><strong>Why?<\/strong><br>\nThe short answer is this:<\/p>\n<p>First, you&#8217;ll change the original information and your team may not approve it.<br>\nSo, ask them first.<\/p>\n<p>Second, all operations involve risk and things may not happen as expected.<br>\nMurphy is elsewhere, unfortunately \u2014 or not, looking the other way around, you may concern that makes our life more exciting and challenging, after all, if everything always works well, life would lose that feeling of risk that turns life so exciting.<\/p>\n<\/div>\n<p>So, better to get prepared to handle &#8220;Murphy&#8221;! \ud83d\ude42<\/p>\n<h2><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"ONE_USE_CASE_AS_AN_EXAMPLE\"><\/span>ONE USE CASE AS AN EXAMPLE<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Performing the master&#8217;s rebasing:<\/p>\n<p>git checkout master<br>\ngit pull &#8211;rebase<\/p>\n<p>Usually, you may get a conflict to solve.<br>\nBasing on <a href=\"https:\/\/docs.github.com\/en\/github\/using-git\/resolving-merge-conflicts-after-a-git-rebase\">GitHub&#8217;s documentation<\/a>, you perform the fix.<\/p>\n<p>As supposed, any documentation must concern about the usual procedure supposing an optimist scenario and sometimes adding extra direction to some issues.<br>\nIssues are part of our IT daily life, always challenging us with unexpected ones.<br>\nBelow, I transcribe parts of its documentation to make things easier (italic).<\/p>\n<p>&nbsp;<\/p>\n<div class=\"article-grid-head\">\n<div class=\"d-flex flex-items-baseline flex-justify-between mt-3\">\n<div class=\"article-grid-head\">\n<div class=\"d-flex flex-items-baseline flex-justify-between mt-3\">\n<h3 class=\"border-bottom-0\"><span class=\"ez-toc-section\" id=\"Resolving_merge_conflicts_after_a_Git_rebase\"><\/span><a href=\"https:\/\/docs.github.com\/en\/github\/using-git\/resolving-merge-conflicts-after-a-git-rebase\"><em>#Resolving merge conflicts after a Git rebase<\/em><\/a><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"d-none d-lg-block ml-2\"><em>When you perform a <code>git rebase<\/code>&nbsp;operation, you&#8217;re typically moving commits around. Because of this, you might get into a situation where a merge conflict is introduced. That means that two of your commits modified the same line in the same file, and Git doesn&#8217;t know which change to apply.<\/em><\/div>\n<\/div>\n<\/div>\n<div class=\"article-grid-toc border-bottom border-xl-0 pb-4 mb-5 pb-xl-0 mb-xl-0\">\n<div class=\"article-grid-toc-content\"><\/div>\n<\/div>\n<div id=\"article-contents\" class=\"article-grid-body\">\n<p><em>After you reorder and manipulate commits using&nbsp;<code>git rebase<\/code>, should a merge conflict occur, Git will tell you so with the following message printed to the terminal:<\/em><\/p>\n<pre><code class=\"hljs language-shell\">error: could not apply fa39187... something to add to patch A\n\nWhen you have resolved this problem, run \"git rebase --continue\".\nIf you prefer to skip this patch, run \"git rebase --skip\" instead.\nTo check out the original branch and stop rebasing, run \"git rebase --abort\".\nCould not apply fa39187f3c3dfd2ab5faa38ac01cf3de7ce2e841... Change fake file<\/code><\/pre>\n<p><em>Here, Git is telling you which commit is causing the conflict (<code>fa39187<\/code>). You&#8217;re given three choices:<\/em><\/p>\n<ul>\n<li><em>You can run&nbsp;<code>git rebase --abort<\/code>&nbsp;to completely undo the rebase. Git will return you to your branch&#8217;s state as it was before&nbsp;<code>git rebase<\/code>&nbsp;was called.<\/em><\/li>\n<li><em>You can run&nbsp;<code>git rebase --skip<\/code>&nbsp;to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included. It is very rare that you would choose this option.<\/em><\/li>\n<li><em>You can fix the conflict.<\/em><\/li>\n<\/ul>\n<p><em>To fix the conflict, you can follow&nbsp;<a href=\"https:\/\/docs.github.com\/en\/articles\/resolving-a-merge-conflict-using-the-command-line\">the standard procedures for resolving merge conflicts from the command line<\/a>. When you&#8217;re finished, you&#8217;ll need to call&nbsp;<code>git rebase --continue<\/code>&nbsp;in order for Git to continue processing the rest of the rebase.<\/em><\/p>\n<h5><\/h5>\n<h2><span class=\"ez-toc-section\" id=\"FIXING_REBASE_CONFLICT_SUMMARY\"><\/span>FIXING REBASE CONFLICT SUMMARY<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To fix the conflict, you can follow&nbsp;<a href=\"https:\/\/docs.github.com\/en\/articles\/resolving-a-merge-conflict-using-the-command-line\">the standard procedures for resolving merge conflicts from the command line<\/a>. When you&#8217;re finished, you&#8217;ll need to call &#8220;<code>git rebase --continue\"<\/code>&nbsp;in order for Git to continue processing the rest of the rebase.<\/p>\n<p>1. To discover the conflicts, do:<br>\ngit status<\/p>\n<p>2. Edit the file that has the conflict and solve it.<\/p>\n<pre class>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD\nThe original code from the current state of the file before the rebase operation\n=======\nThe new code to be merged from the rebase operation\n&gt;&gt;&gt;&gt;&gt;&gt;&gt; branch-a\n<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"FINISH_THE_REBASE_OPERATION_AFTER_FIXING_CONFLICTS\"><\/span>FINISH THE REBASE OPERATION AFTER FIXING CONFLICTS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>3. Add or stage your changes.<br>\ngit add .<\/p>\n<p>4. Commit your changes with a comment.<br>\ngit commit -m &#8220;Resolved merge conflict by incorporating both suggestions.&#8221;<\/p>\n<p>5. Finish rebase:<br>\ngit rebase &#8211;continue<\/p>\n<div id=\"article-contents\" class=\"article-grid-body\">\n<p>@FROM:<br>\n<a href=\"https:\/\/docs.github.com\/en\/github\/collaborating-with-issues-and-pull-requests\/resolving-a-merge-conflict-using-the-command-line\">docs.github.com\/en\/github\/collaborating-with-issues-and-pull-requests\/resolving-a-merge-conflict-using-the-command-line<\/a><\/p>\n<\/div>\n<h5><\/h5>\n<h2><span class=\"ez-toc-section\" id=\"WHEN_GIT_REFUSES_TO_CONTINUE\"><\/span>WHEN GIT REFUSES TO CONTINUE<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The rebase operation takes place:<\/p>\n<p><noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-5691\" src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_1.jpg\" alt width=\"1083\" height=\"938\" srcset=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_1.jpg 1083w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_1-300x260.jpg 300w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_1-768x665.jpg 768w\" sizes=\"(max-width: 1083px) 100vw, 1083px\"><\/noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-5691 lazyload\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201083%20938%22%3E%3C%2Fsvg%3E\" alt width=\"1083\" height=\"938\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201083%20938%22%3E%3C%2Fsvg%3E 1083w\" sizes=\"(max-width: 1083px) 100vw, 1083px\" data-srcset=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_1.jpg 1083w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_1-300x260.jpg 300w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_1-768x665.jpg 768w\" data-src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_1.jpg\"><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>What if, after resolving the merge conflict, the &#8220;git rebase &#8211;continue&#8221; still rejects and continues returning that message: &#8220;the merge must be done&#8221;!<br>\nYou think: I&#8217;ve already solved the conflict, then performed &#8220;git add&#8221;, after performed commit, but it is still refusing.<br>\nWhat do I do?<\/p>\n<p>&nbsp;<\/p>\n<div id=\"article-contents\" class=\"article-grid-body\">\n<p><noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-5692\" src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_2.jpg\" alt width=\"1104\" height=\"671\" srcset=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_2.jpg 1104w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_2-300x182.jpg 300w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_2-768x467.jpg 768w\" sizes=\"(max-width: 1104px) 100vw, 1104px\"><\/noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-5692 lazyload\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201104%20671%22%3E%3C%2Fsvg%3E\" alt width=\"1104\" height=\"671\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201104%20671%22%3E%3C%2Fsvg%3E 1104w\" sizes=\"(max-width: 1104px) 100vw, 1104px\" data-srcset=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_2.jpg 1104w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_2-300x182.jpg 300w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_2-768x467.jpg 768w\" data-src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_rebase_2.jpg\"><\/p>\n<p>&nbsp;<\/p>\n<p>If no other idea comes to mind, well, it is when the third option comes into place: the skip option:<br>\ngit rebase &#8211;skip<\/p>\n<p>The file&#8217;s content is preserved as it is but there is a side effect \u2014 the track of that merge thread will not meet the target thread as usual, getting something like this:<\/p>\n<p>&nbsp;<\/p>\n<p><noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-5693\" src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss.jpg\" alt width=\"1802\" height=\"823\" srcset=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss.jpg 1802w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss-300x137.jpg 300w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss-768x351.jpg 768w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss-1536x702.jpg 1536w\" sizes=\"(max-width: 1802px) 100vw, 1802px\"><\/noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-5693 lazyload\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201802%20823%22%3E%3C%2Fsvg%3E\" alt width=\"1802\" height=\"823\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201802%20823%22%3E%3C%2Fsvg%3E 1802w\" sizes=\"(max-width: 1802px) 100vw, 1802px\" data-srcset=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss.jpg 1802w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss-300x137.jpg 300w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss-768x351.jpg 768w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss-1536x702.jpg 1536w\" data-src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2021\/01\/git_dont_rebase_master_skip_and_info_loss.jpg\"><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>On the right, we have the log before rebasing.<br>\nOn the left, the log after rebasing with a skip operation, where it is lost the merge that originally had for &#8220;c0f92f1&#8221;.<\/p>\n<p><strong>CONCLUSION: some information was lost in the master&#8217;s history.<\/strong><br>\n<strong>Something that is not really desirable.<\/strong><\/p>\n<h2><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"WHEN_SHALL_I_USE_REBASE_THEN%E2%80%A6\"><\/span>WHEN SHALL I USE REBASE, THEN&#8230;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>I think it is useful to rebase your working branch, putting on top of it your current commits.<br>\nIt gives us the chance to handle conflicts as if we had an update (pull) before starting to make our changes in the code.<br>\nThis enables us to a better understanding of what our team has been changing and how it was done out of our interference.<\/p>\n<p>The &#8220;&#8211;continue&#8221; operation fits very well this approach.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>There are many good posts about the differences between pulling with and without rebase, merge and etc. If you desire to refresh memory about this, try these: git: the difference between git pull and git pull \u2013rebase Git Branching and Merge vs Rebase-&nbsp; This post intends to supply information on when and where not to &#8230; <a href=\"https:\/\/ultering.com\/it4us\/?p=5688\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &#8220;Git: Rebase &#8211; When and Where Not To Do&#8221;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[35],"tags":[],"class_list":["post-5688","post","type-post","status-publish","format-standard","hentry","category-versioning"],"_links":{"self":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/5688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5688"}],"version-history":[{"count":6,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/5688\/revisions"}],"predecessor-version":[{"id":7237,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/5688\/revisions\/7237"}],"wp:attachment":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}