<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Git Ops | Haobin Tan</title><link>https://haobin-tan.netlify.app/tags/git-ops/</link><atom:link href="https://haobin-tan.netlify.app/tags/git-ops/index.xml" rel="self" type="application/rss+xml"/><description>Git Ops</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-us</language><lastBuildDate>Fri, 29 Apr 2022 00:00:00 +0000</lastBuildDate><image><url>https://haobin-tan.netlify.app/media/icon_hu7d15bc7db65c8eaf7a4f66f5447d0b42_15095_512x512_fill_lanczos_center_3.png</url><title>Git Ops</title><link>https://haobin-tan.netlify.app/tags/git-ops/</link></image><item><title>Git Squashing</title><link>https://haobin-tan.netlify.app/docs/coding/git/git-operations/git_squash/</link><pubDate>Fri, 29 Apr 2022 00:00:00 +0000</pubDate><guid>https://haobin-tan.netlify.app/docs/coding/git/git-operations/git_squash/</guid><description>&lt;h2 id="what-is-git-squashing">What is Git Squashing?&lt;/h2>
&lt;p>&lt;strong>Git squashing = combine multiple continuous commits into one&lt;/strong>&lt;/p>
&lt;figure>&lt;img src="https://i.ytimg.com/vi/V5KrD7CmO4o/maxresdefault.jpg"
alt="Git squash">&lt;figcaption>
&lt;p>Git squash&lt;/p>
&lt;/figcaption>
&lt;/figure>
&lt;h2 id="when-to-use-git-squashing">When to use Git Squashing?&lt;/h2>
&lt;p>Purpose of Git squashing: to keep the branch graph clean &amp;#x1f4aa;&lt;/p>
&lt;p>Scenarios:&lt;/p>
&lt;details class="spoiler " id="spoiler-1">
&lt;summary class="cursor-pointer">Implementing features&lt;/summary>
&lt;div class="rounded-lg bg-neutral-50 dark:bg-neutral-800 p-2">
Usually, we&amp;rsquo;ll commit multiple times before we reach a satisfactory result, such as some fixes and tests. When we&amp;rsquo;ve implemented the feature, those intermediate commits look redundant. So, in this case, we may want to squash our commits into one.
&lt;/div>
&lt;/details>
&lt;details class="spoiler " id="spoiler-2">
&lt;summary class="cursor-pointer">Merging branches&lt;/summary>
&lt;div class="rounded-lg bg-neutral-50 dark:bg-neutral-800 p-2">
When we start working on a new feature, we&amp;rsquo;ll start a feature branch. Let&amp;rsquo;s say we&amp;rsquo;ve done our work with 20 commits in our feature branch.&lt;/br>So, when we merge the feature branch to the master branch, we want to do a squashing to combine the 20 commits into one. In this way, we keep the master branch clean.
&lt;/div>
&lt;/details>
&lt;h2 id="how-to-git-squashing">How to Git Squashing?&lt;/h2>
&lt;p>We can perform Git squashing via interactive rebase:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">git rebase -i HEAD~&lt;span class="o">{&lt;/span>X&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>X&lt;/code> is the number of commits to be squashed.&lt;/p>
&lt;p>If &lt;code>X&lt;/code> is large and not easy to count, we can find the hash of the commit that we want to rebase &amp;ldquo;onto&amp;rdquo; (by calling &lt;code>git log&lt;/code>) and directly rebase on it:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">git rebase -i &lt;span class="o">{&lt;/span>hash_onto&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="example">Example&lt;/h3>
&lt;p>A nich and clear video tutorial:&lt;/p>
&lt;div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
&lt;iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen="allowfullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/V5KrD7CmO4o?autoplay=0&amp;controls=1&amp;end=0&amp;loop=0&amp;mute=0&amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"
>&lt;/iframe>
&lt;/div>
&lt;p>and its detailed description: &lt;a href="https://www.themoderncoder.com/combining-git-commits-with-squash/">Combining Git commits with squash&lt;/a>&lt;/p>
&lt;h2 id="reference">Reference&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://www.baeldung.com/ops/git-squash-commits">Squash the Last X Commits Using Git&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://www.git-tower.com/learn/git/faq/git-squash">How to Squash Commits in Git&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://gitbook.tw/chapters/rewrite-history/merge-multiple-commits-to-one-commit">【狀況題】把多個 Commit 合併成一個 Commit&lt;/a>&lt;/p>
&lt;/li>
&lt;/ul></description></item></channel></rss>