<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>git &#8211; Bubblog</title>
	<atom:link href="https://blog.yangyuanping.com/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.yangyuanping.com</link>
	<description>nullable reference types</description>
	<lastBuildDate>Fri, 19 Dec 2025 18:17:21 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://blog.yangyuanping.com/wp-content/uploads/2025/11/cropped-patrick_log_logo_251121-2-32x32.png</url>
	<title>git &#8211; Bubblog</title>
	<link>https://blog.yangyuanping.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>从 Git 历史中删除敏感数据</title>
		<link>https://blog.yangyuanping.com/%e4%bb%8e-git-%e5%8e%86%e5%8f%b2%e4%b8%ad%e5%88%a0%e9%99%a4%e6%95%8f%e6%84%9f%e6%95%b0%e6%8d%ae/</link>
		
		<dc:creator><![CDATA[peny911]]></dc:creator>
		<pubDate>Wed, 26 Nov 2025 18:01:34 +0000</pubDate>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[git]]></category>
		<guid isPermaLink="false">https://blog.yangyuanping.com/?p=1041</guid>

					<description><![CDATA[当敏感信息（如密码、密钥、私人域名等）被提交到 Git 仓库后，即使后续提交中删除了这些内容，它们仍然存在于  [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>当敏感信息（如密码、密钥、私人域名等）被提交到 Git 仓库后，即使后续提交中删除了这些内容，它们仍然存在于 Git 历史记录中。本文介绍如何彻底清除这些敏感数据。</p>
<h2>问题场景</h2>
<ul>
<li>不小心提交了 API 密钥、密码</li>
<li>配置文件中包含真实域名或个人信息</li>
<li>已推送到 GitHub 等公开仓库</li>
</ul>
<h2>解决方案&#8217;&quot;</h2>
<h3>方法一：使用 git filter-branch（内置工具）</h3>
<p>适用于替换历史中所有提交的某个文件内容。</p>
<pre><code class="language-bash"># 1. 暂存当前未提交的更改
git stash'"

# 2. 替换历史中所有 README.md 文件里的敏感内容
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --force --tree-filter \
  "find . -name 'README.md' -exec sed -i '' 's/敏感内容/替换内容/g' {} \;" \
  -- --all

# 3. 恢复暂存的更改
git stash pop

# 4. 强制推送到远程仓库（覆盖历史）
git push origin main --force</code></pre>
<h4>参数说明</h4>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>&lt;code&gt;&#8211;force&lt;/code&gt;</td>
<td>强制执行，即使已有备份</td>
</tr>
<tr>
<td>&lt;code&gt;&#8211;tree-filter&lt;/code&gt;</td>
<td>对每个提交的文件树执行命令</td>
</tr>
<tr>
<td>&lt;code&gt;&#8211; &#8211;all&lt;/code&gt;</td>
<td>处理所有分支</td>
</tr>
<tr>
<td>&lt;code&gt;sed -i &#039;&#039;&lt;/code&gt;</td>
<td>macOS 下的原地替换（Linux 用 &lt;code&gt;sed -i&lt;/code&gt;）</td>
</tr>
</tbody>
</table>
<h3>方法二：使用 BFG Repo-Cleaner（推荐，更快）</h3>
<p>适用于删除大文件或敏感文件。</p>
<pre><code class="language-bash"># 安装 BFG
brew install bfg

# 删除某个文件的所有历史
bfg --delete-files 敏感文件.txt

# 或替换敏感文本
bfg --replace-text passwords.txt

# 清理并强制推送
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push origin main --force</code></pre>
<h3>方法三：使用 git filter-repo（官方推荐）</h3>
<pre><code class="language-bash"># 安装
brew install git-filter-repo

# 替换敏感内容
git filter-repo --replace-text &lt;(echo '敏感内容==&gt;替换内容')

# 重新添加远程并推送
git remote add origin https://github.com/user/repo.git
git push origin main --force</code></pre>
<h2>注意事项</h2>
<ol>
<li><strong>强制推送有风险</strong>：会覆盖远程历史，协作者需要重新克隆仓库</li>
<li><strong>轮换密钥</strong>：敏感信息一旦泄露，应立即轮换（如重新生成 API Key）</li>
<li><strong>GitHub 缓存</strong>：GitHub 可能会缓存提交，联系 GitHub 支持可请求清除</li>
<li><strong>本地备份</strong>：操作前建议备份仓库 &lt;code&gt;cp -r .git .git.backup&lt;/code&gt;</li>
</ol>
<h2>预防措施</h2>
<ul>
<li>使用 &lt;code&gt;.gitignore&lt;/code&gt; 忽略敏感文件</li>
<li>使用环境变量存储敏感配置</li>
<li>提交前检查 &lt;code&gt;git diff &#8211;staged&lt;/code&gt;</li>
<li>启用 GitHub 的 Secret Scanning 功能</li>
</ul>
<h2>总结</h2>
<ol>
<li>git stash &#8211; 暂存当前未提交的更改</li>
<li>git filter-branch &#8211;tree-filter &#8211; 遍历所有历史提交，用 sed 替换敏感内容</li>
<li>git stash pop &#8211; 恢复暂存的更改</li>
<li>git push &#8211;force &#8211; 强制推送覆盖远程历史</li>
</ol>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Windows 下的 Bash 环境设置代理</title>
		<link>https://blog.yangyuanping.com/windows-%e4%b8%8b%e7%9a%84-bash-%e7%8e%af%e5%a2%83%e8%ae%be%e7%bd%ae%e4%bb%a3%e7%90%86/</link>
		
		<dc:creator><![CDATA[peny911]]></dc:creator>
		<pubDate>Tue, 11 Nov 2025 08:04:17 +0000</pubDate>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[proxy]]></category>
		<guid isPermaLink="false">https://blog.yangyuanping.com/?p=962</guid>

					<description><![CDATA[🌍 一、全局环境变量方式（推荐用于临时代理） Git Bash 是基于 MinGW + Bash 的，因此语法 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f30d.png" alt="🌍" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 一、全局环境变量方式（推荐用于临时代理）</h2>



<p>Git Bash 是基于 MinGW + Bash 的，因此语法与 Linux 一致。</p>



<p>1&#x20e3; 设置 HTTP / HTTPS 代理</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>export http_proxy=http://127.0.0.1:10808
export https_proxy=http://127.0.0.1:10808</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">export</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">http_proxy</span><span style="color: #81A1C1">=</span><span style="color: #A3BE8C">http://127.0.0.1:10808</span></span>
<span class="line"><span style="color: #81A1C1">export</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">https_proxy</span><span style="color: #81A1C1">=</span><span style="color: #A3BE8C">http://127.0.0.1:10808</span></span></code></pre></div>



<p>如果你的代理需要用户名密码：</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>export http_proxy=http://user:password@127.0.0.1:10808</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">export</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">http_proxy</span><span style="color: #81A1C1">=</span><span style="color: #A3BE8C">http://user:password@127.0.0.1:10808</span></span></code></pre></div>



<p>2&#x20e3; 验证是否设置成功</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>echo $http_proxy
echo $https_proxy</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">echo</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">$http_proxy</span></span>
<span class="line"><span style="color: #88C0D0">echo</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">$https_proxy</span></span></code></pre></div>



<p>3&#x20e3; 测试是否生效</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>curl https://ipinfo.io</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">curl</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">https://ipinfo.io</span></span></code></pre></div>



<p>如果返回的 IP 地址与你本地不同（或与代理服务器一致），说明代理生效。<br>若不生效，可以强制使用：</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>curl -x $http_proxy https://ipinfo.io</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">curl</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">-x</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">$http_proxy</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">https://ipinfo.io</span></span></code></pre></div>



<p>4&#x20e3; 临时取消代理</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>unset http_proxy
unset https_proxy</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">unset</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http_proxy</span></span>
<span class="line"><span style="color: #88C0D0">unset</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">https_proxy</span></span></code></pre></div>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p></p>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f527.png" alt="🔧" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 二、Git 自身的代理设置（推荐用于 Git 命令）</h2>



<p>Git 不一定会读取系统环境变量，因此可以单独设置：</p>



<p>1&#x20e3; 设置全局 Git 代理</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>git config --global http.proxy http://127.0.0.1:10808
git config --global https.proxy http://127.0.0.1:10808</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">git</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">config</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--global</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http.proxy</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://127.0.0.1:10808</span></span>
<span class="line"><span style="color: #88C0D0">git</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">config</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--global</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">https.proxy</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://127.0.0.1:10808</span></span></code></pre></div>



<p>2&#x20e3; 查看当前配置</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>git config --global --get http.proxy
git config --global --get https.proxy</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">git</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">config</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--global</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--get</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http.proxy</span></span>
<span class="line"><span style="color: #88C0D0">git</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">config</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--global</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--get</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">https.proxy</span></span></code></pre></div>



<p>3&#x20e3; 取消代理</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>git config --global --unset http.proxy
git config --global --unset https.proxy</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">git</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">config</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--global</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--unset</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http.proxy</span></span>
<span class="line"><span style="color: #88C0D0">git</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">config</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--global</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--unset</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">https.proxy</span></span></code></pre></div>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4a1.png" alt="💡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 推荐组合使用场景</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>目的</th><th>推荐做法</th></tr></thead><tbody><tr><td>临时想让 <code>curl</code>、<code>npm</code>、<code>dotnet restore</code> 等命令都走代理</td><td>用 <code>export http_proxy</code> 和 <code>https_proxy</code></td></tr><tr><td>只想让 <code>git clone/pull/push</code> 走代理</td><td>用 <code>git config --global http.proxy</code></td></tr><tr><td>想永久生效</td><td>把 <code>export</code> 命令加进 <code>~/.bashrc</code> 或 <code>~/.bash_profile</code></td></tr></tbody></table></figure>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>在 .Net 项目中使用 Git Submodule</title>
		<link>https://blog.yangyuanping.com/%e5%9c%a8-net-%e9%a1%b9%e7%9b%ae%e4%b8%ad%e4%bd%bf%e7%94%a8-git-submodule/</link>
		
		<dc:creator><![CDATA[peny911]]></dc:creator>
		<pubDate>Sat, 18 Oct 2025 05:04:12 +0000</pubDate>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[Submodule]]></category>
		<guid isPermaLink="false">https://blog.yangyuanping.com/?p=945</guid>

					<description><![CDATA[在 .NET Core 项目中使用 Git Submodule 的场景通常是：你有一些公共的库、工具类、UI  [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>在 .NET Core 项目中使用 <strong>Git Submodule</strong> 的场景通常是：你有一些公共的库、工具类、UI 组件或 SDK，希望在多个项目中复用，同时又希望保持它们作为独立仓库进行开发和维护。这时候用 <strong>submodule</strong> 就很合适。下面是完整的使用步骤和注意事项。</p>
<hr />
<h2>一、添加 Submodule</h2>
<ol>
<li>在主项目仓库中执行：</li>
</ol>
<pre><code class="language-bash">git submodule add https://github.com/your-org/your-library.git src/YourLibrary</code></pre>
<ol start="2">
<li>初始化并更新 submodule：</li>
</ol>
<pre><code class="language-bash">git submodule update --init --recursive</code></pre>
<ol start="3">
<li>提交变更：</li>
</ol>
<pre><code class="language-bash">git add .gitmodules src/YourLibrary
git commit -m "Add submodule YourLibrary"</code></pre>
<hr />
<h2>二、在 .NET Core 项目中引用</h2>
<p>有两种常见方式：</p>
<h3>方式 1：直接作为项目引用</h3>
<ol>
<li>在主解决方案中添加子项目：</li>
</ol>
<pre><code class="language-bash">dotnet sln add src/YourLibrary/YourLibrary.csproj</code></pre>
<ol start="2">
<li>在主项目中引用：</li>
</ol>
<pre><code class="language-bash">dotnet add src/MainProject/MainProject.csproj reference src/YourLibrary/YourLibrary.csproj</code></pre>
<p>这样子模块的代码会直接参与编译和调试。</p>
<hr />
<h3>方式 2：作为 NuGet 包</h3>
<p>如果子模块仓库本身会打包成 NuGet 包，可以：</p>
<ol>
<li>在子模块目录里生成包：</li>
</ol>
<pre><code class="language-bash">cd src/YourLibrary
dotnet pack -c Release</code></pre>
<ol start="2">
<li>在主项目中添加本地源或上传到私有 NuGet Server，然后引用。</li>
</ol>
<p>这种方式更适合多人协作或多个项目依赖同一个库的场景。</p>
<hr />
<h2>三、更新 Submodule</h2>
<p>当子模块仓库有更新时：</p>
<pre><code class="language-bash">cd src/YourLibrary
git checkout main
git pull origin main
cd ../..
git add src/YourLibrary
git commit -m "Update YourLibrary submodule"</code></pre>
<p>主项目会记录子模块的 commit id。团队成员只需执行：</p>
<pre><code class="language-bash">git submodule update --init --recursive</code></pre>
<p>就能保持一致。</p>
<hr />
<h2>四、注意事项</h2>
<ol>
<li>
<p><strong>避免循环依赖</strong>：子模块不能再依赖主项目。</p>
</li>
<li>
<p><strong>团队协作</strong>：确保大家 clone 时用 &lt;code&gt;&#8211;recursive&lt;/code&gt;：</p>
<pre><code class="language-bash">git clone --recursive https://github.com/your-org/your-project.git</code></pre>
</li>
<li>
<p><strong>切换分支</strong>：记得子模块也可能需要单独切换分支。</p>
</li>
<li>
<p><strong>CI/CD</strong>：在 CI 脚本中要执行 &lt;code&gt;git submodule update &#8211;init &#8211;recursive&lt;/code&gt;。</p>
</li>
</ol>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
