<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Git on 南山小记</title><link>https://z2n8q.667775.xyz/tags/git/</link><description>Recent content in Git on 南山小记</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Sun, 19 Jul 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://z2n8q.667775.xyz/tags/git/index.xml" rel="self" type="application/rss+xml"/><item><title>我的 Git 分支习惯</title><link>https://z2n8q.667775.xyz/posts/git-branch-workflow/</link><pubDate>Sun, 19 Jul 2026 00:00:00 +0000</pubDate><guid>https://z2n8q.667775.xyz/posts/git-branch-workflow/</guid><description>分支的创建、切换、合并、回滚。</description><content:encoded><![CDATA[<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git switch -c feature/login     <span style="color:#75715e"># 新建并切换</span>
</span></span><span style="display:flex;"><span>git switch main
</span></span><span style="display:flex;"><span>git branch -d feature/login     <span style="color:#75715e"># 删除已合并分支</span>
</span></span></code></pre></div><h2 id="合并-vs-变基">合并 vs 变基</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git merge feature/login
</span></span><span style="display:flex;"><span>git rebase main
</span></span></code></pre></div><p>merge 保留分叉历史，rebase 拉成直线。团队协作一般用 merge，个人分支整理用 rebase。</p>
<h2 id="回滚">回滚</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git reset --soft HEAD~1     <span style="color:#75715e"># 撤销提交，保留改动</span>
</span></span><span style="display:flex;"><span>git reset --hard HEAD~1     <span style="color:#75715e"># 撤销提交，丢弃改动</span>
</span></span><span style="display:flex;"><span>git revert &lt;commit&gt;         <span style="color:#75715e"># 生成一个反向提交</span>
</span></span></code></pre></div><h2 id="已经推上去的分支">已经推上去的分支</h2>
<p>不要 <code>reset --hard</code> 后强推，会用 <code>revert</code>。强推会让别人的历史对不上。</p>
]]></content:encoded></item></channel></rss>