<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>工作流 - 标签 - Vindrin</title><link>https://vindrin.top/zh-cn/tags/%E5%B7%A5%E4%BD%9C%E6%B5%81/</link><description>工作流 - 标签 - Vindrin</description><generator>Hugo -- gohugo.io</generator><language>zh-CN</language><managingEditor>vindrin@outlook.com (Vindrin)</managingEditor><webMaster>vindrin@outlook.com (Vindrin)</webMaster><lastBuildDate>Tue, 10 Mar 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://vindrin.top/zh-cn/tags/%E5%B7%A5%E4%BD%9C%E6%B5%81/" rel="self" type="application/rss+xml"/><item><title>搞懂 Git Rebase 和 Merge 的区别</title><link>https://vindrin.top/zh-cn/posts/git-rebase-vs-merge/</link><pubDate>Tue, 10 Mar 2026 00:00:00 +0000</pubDate><author>vindrin@outlook.com (Vindrin)</author><guid>https://vindrin.top/zh-cn/posts/git-rebase-vs-merge/</guid><description><![CDATA[<h1 id="搞懂-git-rebase-和-merge-的区别">搞懂 Git Rebase 和 Merge 的区别</h1>
<p>这个问题几乎困扰过每一个开发者，今天来讲清楚。</p>
<h2 id="merge">Merge</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="复制到剪贴板"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">git checkout main
</span></span><span class="line"><span class="cl">git merge feature-branch</span></span></code></pre></div></div>
<p>会创建一个<strong>合并提交</strong>。历史记录清晰展示了两条分支在某个节点汇合。适合共享分支。</p>
<h2 id="rebase">Rebase</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="复制到剪贴板"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">git checkout feature-branch
</span></span><span class="line"><span class="cl">git rebase main</span></span></code></pre></div></div>
<p>将你的提交&quot;移植&quot;到 <code>main</code> 最新节点之后。历史记录看起来是<strong>线性的</strong>，就像你是在 main 更新后才开始做功能一样。</p>
<h2 id="什么时候用哪个">什么时候用哪个？</h2>
<table>
  <thead>
      <tr>
          <th>场景</th>
          <th>推荐方式</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>共享分支（main、dev）</td>
          <td><code>merge</code></td>
      </tr>
      <tr>
          <td>个人功能分支</td>
          <td><code>rebase</code></td>
      </tr>
      <tr>
          <td>提 PR 之前整理提交</td>
          <td><code>rebase</code></td>
      </tr>
      <tr>
          <td>PR 合并后</td>
          <td>无所谓</td>
      </tr>
  </tbody>
</table>
<h2 id="黄金原则">黄金原则</h2>
<p><strong>永远不要对别人正在用的分支做 rebase。</strong> 重写共享历史会把所有人搞乱。</p>]]></description></item></channel></rss>