<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>orhan.cn - cargo</title>
    <link rel="self" type="application/atom+xml" href="https://orhan.cn/tags/cargo/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://orhan.cn"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-03-06T00:00:00+00:00</updated>
    <id>https://orhan.cn/tags/cargo/atom.xml</id>
    <entry xml:lang="en">
        <title>Git 分支重置到之前的提交</title>
        <published>2026-03-06T00:00:00+00:00</published>
        <updated>2026-03-06T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              menzil
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://orhan.cn/posts/git-reset-branch-to-previous-commit/"/>
        <id>https://orhan.cn/posts/git-reset-branch-to-previous-commit/</id>
        
        <content type="html" xml:base="https://orhan.cn/posts/git-reset-branch-to-previous-commit/">&lt;h2 id=&quot;wen-ti-miao-shu&quot;&gt;问题描述&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#wen-ti-miao-shu&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;在运行 &lt;code&gt;cargo watch -x &#x27;run -p gateway&#x27;&lt;&#x2F;code&gt; 时遇到错误：&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#2b303b;color:#c0c5ce;&quot;&gt;&lt;code&gt;&lt;span&gt;error: failed to load manifest for workspace member
&lt;&#x2F;span&gt;&lt;span&gt;referenced by workspace at `&#x2F;path&#x2F;to&#x2F;Cargo.toml`
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;Caused by:
&lt;&#x2F;span&gt;&lt;span&gt;  failed to load manifest for dependency `module-store`
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;Caused by:
&lt;&#x2F;span&gt;&lt;span&gt;  failed to read `&#x2F;path&#x2F;to&#x2F;modules&#x2F;store&#x2F;Cargo.toml`
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;Caused by:
&lt;&#x2F;span&gt;&lt;span&gt;  No such file or directory (os error 2)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;原因是 &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt; 中的 workspace members 列表包含了 &lt;code&gt;modules&#x2F;store&lt;&#x2F;code&gt; 和 &lt;code&gt;modules&#x2F;merchant&lt;&#x2F;code&gt;，但这些目录实际上不存在。这是由于之前的错误提交导致的。&lt;&#x2F;p&gt;
&lt;h2 id=&quot;jie-jue-fang-an&quot;&gt;解决方案&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#jie-jue-fang-an&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;1-que-ren-zheng-que-de-ti-jiao&quot;&gt;1. 确认正确的提交&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#1-que-ren-zheng-que-de-ti-jiao&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;首先查看提交历史，找到最后一个正常工作的提交：&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; log&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; --oneline
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;确认目标提交是 &lt;code&gt;14b6cf9&lt;&#x2F;code&gt; (use orm fixed n+1)。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;2-zhong-zhi-fen-zhi&quot;&gt;2. 重置分支&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#2-zhong-zhi-fen-zhi&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;如果当前在 detached HEAD 状态，可以使用以下方法：&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# 方法一：强制将 main 分支指向当前 HEAD，然后切换到 main
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; branch&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span&gt; main HEAD &amp;amp;&amp;amp; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; checkout main
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# 方法二：切换回 main 分支，然后重置到目标提交
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; checkout main
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; reset&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; --hard&lt;&#x2F;span&gt;&lt;span&gt; 14b6cf9
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;如果已经在 main 分支上：&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# 直接重置
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; reset&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; --hard&lt;&#x2F;span&gt;&lt;span&gt; 14b6cf9
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;3-tui-song-dao-yuan-cheng-ke-xuan&quot;&gt;3. 推送到远程（可选）&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#3-tui-song-dao-yuan-cheng-ke-xuan&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;如果需要更新远程仓库，使用 force push：&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; push origin main&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; --force
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;⚠️ 注意&lt;&#x2F;strong&gt;：&lt;code&gt;--force&lt;&#x2F;code&gt; 会覆盖远程历史记录，如果团队中有其他人在使用该分支，请先沟通确认。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;4-yan-zheng&quot;&gt;4. 验证&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#4-yan-zheng&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# 查看当前分支和状态
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; branch&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; --show-current
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; status
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# 查看最近的提交
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; log&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; --oneline -5
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;xiang-guan-zhi-shi&quot;&gt;相关知识&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#xiang-guan-zhi-shi&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;git-reset-hard-de-zuo-yong&quot;&gt;git reset --hard 的作用&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#git-reset-hard-de-zuo-yong&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;移动 HEAD 指针到指定提交&lt;&#x2F;li&gt;
&lt;li&gt;重置暂存区（staging area）&lt;&#x2F;li&gt;
&lt;li&gt;重置工作目录（working directory）&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;会丢失所有未提交的更改&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;detached-head-zhuang-tai&quot;&gt;Detached HEAD 状态&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#detached-head-zhuang-tai&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;当你直接 checkout 到某个提交（而不是分支）时，会进入 detached HEAD 状态。此时的修改不属于任何分支，需要创建新分支或切换回已有分支。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;geng-an-quan-de-ti-dai-fang-an&quot;&gt;更安全的替代方案&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#geng-an-quan-de-ti-dai-fang-an&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;如果不想使用 &lt;code&gt;--hard&lt;&#x2F;code&gt;，可以考虑：&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# 创建备份分支
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; branch backup-branch
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# 使用 revert 撤销提交（保留历史）
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; revert &amp;lt;commit-hash&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# 或使用 reset --soft（保留更改在暂存区）
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; reset&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; --soft &lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;commit-hash&amp;gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;zong-jie&quot;&gt;总结&lt;a class=&quot;anchor&quot; aria-hidden=&quot;true&quot; href=&quot;#zong-jie&quot; hidden=&quot;&quot;&gt;#&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;遇到 Cargo workspace 成员缺失的问题时，首先检查 &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt; 中的 members 列表是否与实际目录结构匹配。如果是由错误提交导致的，可以使用 &lt;code&gt;git reset --hard&lt;&#x2F;code&gt; 快速回退到正确的状态。&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Rust Best Crates</title>
        <published>2025-09-23T00:00:00+00:00</published>
        <updated>2025-09-23T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              menzil
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://orhan.cn/posts/best-crates/"/>
        <id>https://orhan.cn/posts/best-crates/</id>
        
        <content type="html" xml:base="https://orhan.cn/posts/best-crates/">&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;pgrx&quot;&gt;Build Postgres Extensions with Rust!&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;mry&quot;&gt;Mry A simple but powerful mocking library for structs, traits, and function.&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;rumqttc&quot;&gt;rumqttc&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;postgrest&quot;&gt;postgrest&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</content>
        
    </entry>
</feed>
