/post/2019-06-17-avoid-rebase-hell-squashing-wi/index.html
HTML | 282 lines | 205 code | 76 blank | 1 comment | 0 complexity | e636e173ca43eeb76e436e0bf08ae878 MD5 | raw file
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <title>Avoid rebase hell: squashing without rebasing · The Odd Bit</title>
- <meta name="description" content="You’re working on a pull request. You’ve been working on a pull request for a while, and due to lack of sleep or inebriation you’ve been merging changes into your feature branch rather than rebasing. You now have a pull request that looks like this (I’ve marked merge commits with the text [merge]):
- 7e181479 Adds methods for widget sales 0487162 [merge] Merge remote-tracking branch 'origin/master' into my_feature 76ee81c [merge] Merge branch 'my_feature' of https://github.">
- <meta name="HandheldFriendly" content="True">
- <meta name="MobileOptimized" content="320">
- <meta name="generator" content="Hugo 0.88.0" />
- <meta name="robots" content="index,follow">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-
-
-
- <link rel="stylesheet" href="https://blog.oddbit.com/dist/style.min.81747fa30e7c939c160ea84909a818dc1b99d7e662edf55326bd32a4510c9eb5.css">
- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&subset=latin,cyrillic-ext,latin-ext,cyrillic">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
-
- <!-- alternate output formats -->
- <link rel="stylesheet" href="/css/oddbit.css">
- <link rel="stylesheet" href="/css/sx.css">
- <link rel="stylesheet" href="/css/pull-request.css">
- <link rel="stylesheet" href="/css/archive.css">
- <link rel="stylesheet" href="/css/syntax.css">
-
- </head>
- <body>
-
- <div id="wrapper">
- <header class="site-header">
- <div class="container">
- <div class="site-title-wrapper">
-
- <h1 class="site-title">
- <a title="The Odd Bit" href="https://blog.oddbit.com/">The Odd Bit</a>
- </h1>
-
- <a class="button-square" href="https://blog.oddbit.com/rss.xml"><i class="fa fa-rss"></i></a>
-
- <a class="button-square button-social hint--top" data-hint="Twitter" title="Twitter" href="https://twitter.com/larsks" rel="me">
- <i class="fa fa-twitter"></i>
- </a>
-
-
-
-
- <a class="button-square button-social hint--top" data-hint="Github" title="Github" href="https://github.com/larsks" rel="me">
- <i class="fa fa-github-alt"></i>
- </a>
-
-
- <a class="button-square button-social hint--top" data-hint="Stack Overflow" title="Stack Overflow" href="https://stackoverflow.com/users/147356/larsks" rel="me">
- <i class="fa fa-stack-overflow"></i>
- </a>
-
-
-
-
- </div>
- <div class="donate">
- If you find something here useful or interesting, you can
- <a href="https://www.buymeacoffee.com/oddbit">buy me a coffee</a>!
- </div>
- <ul class="site-nav">
-
- <li class="site-nav-item">
- <a title="Home" href="/">Home</a>
- </li>
- <li class="site-nav-item">
- <a title="Categories" href="/categories">Categories</a>
- </li>
- <li class="site-nav-item">
- <a title="Tags" href="/tags">Tags</a>
- </li>
- <li class="site-nav-item">
- <a title="Archives" href="/archives">Archives</a>
- </li>
- <li class="site-nav-item">
- <a title="Answers" href="/about/stackoverflow/">Answers</a>
- </li>
- <li class="site-nav-item">
- <a title="GPG Key" href="/about/gpg/">GPG Key</a>
- </li>
- </ul>
- </div>
- </header>
- <div id="container">
- <div class="container">
- <article class="post-container" itemscope="" itemtype="http://schema.org/BlogPosting">
- <header class="post-header">
- <h1 class="post-title" itemprop="name headline">Avoid rebase hell: squashing without rebasing</h1>
-
- <p class="post-date post-line">
- <span>Published <time datetime="2019-06-17" itemprop="datePublished">Mon, Jun 17, 2019</time></span>
- <span>by</span>
- <span itemscope="" itemprop="author" itemtype="https://schema.org/Person">
- <span itemprop="name">
- <a href="/about/" itemprop="url" rel="author">Lars Kellogg-Stedman</a>
- </span>
- </span>
- </p>
-
- </header>
- <div class="post-content clearfix" itemprop="articleBody">
-
-
- <p>You’re working on a pull request. You’ve been working on a pull request for a while, and due to lack of sleep or inebriation you’ve been merging changes into your feature branch rather than rebasing. You now have a pull request that looks like this (I’ve marked merge commits with the text <code>[merge]</code>):</p>
- <pre tabindex="0"><code>7e181479 Adds methods for widget sales
- 0487162 [merge] Merge remote-tracking branch 'origin/master' into my_feature
- 76ee81c [merge] Merge branch 'my_feature' of https://github.com/my_user_name/widgets into my_feature
- 981aab4 Adds api for the widget service.
- b048836 Includes fixes suggested by reviewer.
- 3dd0c22 adds changes requested by reviewer
- 5891db2 [merge] fixing merge conflicts
- 2e226e4 fixes suggestions given by the reviewer
- da1e85c Adds gadget related API spec
- c555cc1 Adds doodad related API spec
- e5beb3e Adds api for update and delete of widgets
- c43bade Adds api for creating widgets
- deaa962 Adds all get methods for listing widgets
- 9de79ab Adds api for showing a widget and simple data model
- 8288ab1 Adds api framework for widget service
- </code></pre><p>You know that’s a mess, so you try to fix it by running <code>git rebase -i master</code> and squashing everything together…and you find yourself stuck in an endless maze of merge conflicts. There has to be a better way!</p>
- <p><em>(voiceover: there is a better way…)</em></p>
- <h2 id="option-1-merge---squash">Option 1: merge –squash</h2>
- <p>In this method, you will create a temporary branch and use <code>git merge --squash</code> to squash together the changes in your pull request.</p>
- <ol>
- <li>
- <p>Check out a new branch based on <code>master</code> (or the appropriate base branch if your feature branch isn’t based on <code>master</code>):</p>
- <pre tabindex="0"><code>git checkout -b work master
- </code></pre><p>(This creates a new branch called <code>work</code> and makes that your current branch.)</p>
- </li>
- <li>
- <p>Bring in the changes from your messy pull request using <code>git merge --squash</code>:</p>
- <pre tabindex="0"><code>git merge --squash my_feature
- </code></pre><p>This brings in all the changes from your <code>my_feature</code> branch and stages them, but does not create <em>any</em> commits.</p>
- </li>
- <li>
- <p>Commit the changes with an appropriate commit message:</p>
- <pre tabindex="0"><code>git commit
- </code></pre><p>At this point, your <code>work</code> branch should be identical to the original <code>my_feature</code> branch (running <code>git diff my_feature_branch</code> should not show any changes), but it will have only a single commit after <code>master</code>.</p>
- </li>
- <li>
- <p>Return to your feature branch and <code>reset</code> it to the squashed version:</p>
- <pre tabindex="0"><code>git checkout my_feature
- git reset --hard work
- </code></pre></li>
- <li>
- <p>Update your pull request:</p>
- <pre tabindex="0"><code>git push -f
- </code></pre></li>
- <li>
- <p>Optionally clean up your work branch:</p>
- <pre tabindex="0"><code>git branch -D work
- </code></pre></li>
- </ol>
- <h2 id="option-2-using-git-commit-tree">Option 2: Using <code>git commit-tree</code></h2>
- <p>In this method, you will use <code>git commit-tree</code> to create a new commit without requiring a temporary branch.</p>
- <ol>
- <li>
- <p>Use <code>git commit-tree</code> to create new commit that reproduces the current state of your <code>my_feature</code> branch but</p>
- <pre tabindex="0"><code>git commit-tree -p master -m 'this implements my_feature' my_feature^{tree}
- </code></pre><p>This uses the current state of the <code>my_feature</code> branch as the source of a new commit whose parent is <code>master</code>. This will print out a commit hash:</p>
- <pre tabindex="0"><code>1d3917a3b7c43f4585084e626303c9eeee59c6d6
- </code></pre></li>
- <li>
- <p>Reset your <code>my_feature</code> branch to this new commit hash:</p>
- <pre tabindex="0"><code>git reset --hard 1d3917a3b7c43f4585084e626303c9eeee59c6d6
- </code></pre></li>
- <li>
- <p>Consider editing your commit message to meet <a href="https://blog.oddbit.com/post/2019-06-14-git-etiquette-commit-messages/">best practices</a>.</p>
- </li>
- <li>
- <p>Update your pull request:</p>
- <pre tabindex="0"><code>git push -f
- </code></pre></li>
- </ol>
- </div>
- <footer class="post-footer clearfix">
-
- <p class="post-tags">
- <span>Tagged:</span>
-
-
-
-
- <a href="https://blog.oddbit.com/tag/git/">git</a>
-
-
- </p>
-
- <div class="share">
-
- <a class="icon-twitter" href="https://twitter.com/share?text=Avoid%20rebase%20hell%3a%20squashing%20without%20rebasing&url=https%3a%2f%2fblog.oddbit.com%2fpost%2f2019-06-17-avoid-rebase-hell-squashing-wi%2f"
- onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;">
- <i class="fa fa-twitter"></i>
- <span class="hidden">Twitter</span>
- </a>
-
-
-
-
- </div>
- </footer>
- <script src="https://utteranc.es/client.js"
- repo="larsks/blog.oddbit.com"
- issue-term="pathname"
- label="comment"
- theme="github-light"
- crossorigin="anonymous"
- async>
- </script>
- </article>
- </div>
- </div>
- </div>
- <footer class="footer">
- <div class="container">
- <div class="site-title-wrapper">
- <h1 class="site-title">
- <a title="The Odd Bit" href="https://blog.oddbit.com/">The Odd Bit</a>
- </h1>
- <a class="button-square button-jump-top js-jump-top" href="#">
- <i class="fa fa-angle-up"></i>
- </a>
- </div>
- <p class="footer-copyright">
- <span>© 2022 / Powered by <a href="https://gohugo.io/">Hugo</a></span>
- </p>
- <p class="footer-copyright">
- <span><a href="https://github.com/roryg/ghostwriter">Ghostwriter theme</a> By <a href="http://jollygoodthemes.com">JollyGoodThemes</a></span>
- <span>/ <a href="https://github.com/jbub/ghostwriter">Ported</a> to Hugo By <a href="https://github.com/jbub">jbub</a></span>
- </p>
- </div>
- </footer>
- <script src="https://blog.oddbit.com/js/jquery-1.11.3.min.js"></script>
- <script src="https://blog.oddbit.com/js/jquery.fitvids.js"></script>
-
-
- <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
-
-
- <script src="https://blog.oddbit.com/js/scripts.js"></script>
- </body>
- </html>