blog-hexo/public/posts/25246/index.html
2023-12-26 12:54:52 +08:00

669 lines
74 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Git
</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="Mozzie">
<link rel="canonical" href="https://mozzie.cn/posts/25246/">
<link rel="icon" type="image/svg" href='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 7h1a2 2 0 0 1 2 2v.5a.5.5 0 0 0 .5.5a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-.5.5a.5.5 0 0 0-.5.5v.5a2 2 0 0 1-2 2h-2"></path><path d="M8 7H6a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h1"></path><path d="M12 8l-2 4h3l-2 4"></path></g></svg>'>
<link rel="stylesheet" href="/css/b2495cef.css">
<script>window.i18n = {"tip-status-done":"完成","tip-status-default":"全部","tip-status-todo":"计划","tip-status-doing":"进行","tip-status-other":"其他","text-select":"选择","text-move":"移动","text-esc":"退出","January":"一月","February":"二月","March":"三月","April":"四月","May":"五月","June":"六月","July":"七月","August":"八月","September":"九月","October":"十月","November":"十一月","December":"十二月"}</script>
<meta name="generator" content="Hexo 7.0.0"></head>
<body id="app">
<aside id="aside-box" class="left-aside">
<div class="header">
<link rel="stylesheet" href="/css/61875ce9.css">
<div class="profile">
<a class="badge" href="/">
<span>Hi</span>
<span>Mozzie</span>
</a>
<cosy-tooltip id="left-aside-button" placement="right">
<span slot="content">
<span>显示 / 隐藏 左侧导航</span>
<cosy-short-key>[</cosy-short-key>
</span>
<cosy-icon>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20">
<g fill="none">
<path d="M16 4c1.104-.019 2 .896 2 2v8a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h12zm1 2a1 1 0 0 0-1-1h-2.995v10H16a1 1 0 0 0 1-1V6zm-4.995 9V5H4.001a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8.004z" fill="currentColor"></path>
</g>
</svg>
</cosy-icon>
</cosy-tooltip>
</div>
<script src="/js/a66044b6.js"></script>
<cosy-search id="post-search" placeholder="搜索">
<div slot="short-key">
<cosy-short-key></cosy-short-key>
<cosy-short-key>K</cosy-short-key>
</div>
</cosy-search>
<script>
window.algolia = {
appId: "5DTW808BZ8",
SearchOnlyAPIKey: "27845b245efc8a2853cc0bdc7366ea26"
}
</script>
<script src="/js/5f00f278.js"></script>
</div>
<div class="aside-category">
<link rel="stylesheet" href="/css/db04a759.css">
<nav class="category-nav cosy-scrollbar">
<ul><li data-path="archives">
<a href="/archives">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20"><g fill="none"><path d="M3.5 3A1.5 1.5 0 0 0 2 4.5v4A1.5 1.5 0 0 0 3.5 10h9A1.5 1.5 0 0 0 14 8.5v-4A1.5 1.5 0 0 0 12.5 3h-9zM3 4.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5v-4zm.5 6.5A1.5 1.5 0 0 0 2 12.5v4A1.5 1.5 0 0 0 3.5 18h9a1.5 1.5 0 0 0 1.5-1.5v-4a1.5 1.5 0 0 0-1.5-1.5h-9zM3 12.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5v-4zm14-.063a2.003 2.003 0 0 1-2.5-1.937A2 2 0 0 1 16 8.563a2.005 2.005 0 0 1 1 0a2 2 0 0 1 0 3.874zM16.5 3a.5.5 0 0 1 .5.5v4.041a3.02 3.02 0 0 0-1 0V3.5a.5.5 0 0 1 .5-.5zm0 10.5c-.17 0-.337-.014-.5-.041V17.5a.5.5 0 0 0 1 0v-4.041c-.163.027-.33.041-.5.041z" fill="currentColor"></path></g></svg>
<div class="ellipsis">归档</div>
</a>
</li><li data-path="cosy-roadmap">
<a href="/cosy-roadmap">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20"><g fill="none"><path d="M9.384 2a1 1 0 0 0-.966.742L4.616 17H2.5a.5.5 0 0 0 0 1h15a.5.5 0 0 0 0-1h-2.116L11.582 2.742A1 1 0 0 0 10.616 2H9.384zM5.651 17l.8-3H11.5a.5.5 0 0 0 0-1H6.717l.534-2H10.5a.5.5 0 0 0 0-1H7.517l1.867-7h1.232l3.733 14H5.651z" fill="currentColor"></path></g></svg>
<div class="ellipsis">路线图</div>
</a>
</li><li data-path="cosy-resume">
<a href="/cosy-resume">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20"><g fill="none"><path d="M8.5 4.498a1.5 1.5 0 1 1 3 0a1.5 1.5 0 0 1-3 0zm1.5-2.5a2.5 2.5 0 0 0-2.43 3.086L5.471 4.15a1.761 1.761 0 0 0-2.317.88c-.4.882-.008 1.917.877 2.31L7 8.662v2.287l-1.877 4.645a1.75 1.75 0 0 0 3.245 1.311l1.556-3.849a.073.073 0 0 1 .028-.038a.086.086 0 0 1 .046-.012c.02 0 .035.005.046.012a.074.074 0 0 1 .028.038l1.555 3.849a1.75 1.75 0 0 0 3.245-1.311L13 10.96V8.662l2.968-1.322a1.74 1.74 0 0 0 .877-2.31a1.761 1.761 0 0 0-2.317-.88l-2.097.934a2.5 2.5 0 0 0-2.43-3.086zM4.065 5.444a.761.761 0 0 1 1-.38l3.918 1.744a2.5 2.5 0 0 0 2.034 0l3.918-1.744a.761.761 0 0 1 1 .38a.739.739 0 0 1-.373.983l-2.969 1.321a1 1 0 0 0-.593.914v2.298a1 1 0 0 0 .073.375l1.872 4.633a.75.75 0 0 1-1.39.562l-1.556-3.849c-.364-.9-1.639-.9-2.003 0l-1.555 3.85a.75.75 0 1 1-1.39-.562l1.876-4.646A1 1 0 0 0 8 10.95V8.662a1 1 0 0 0-.593-.914L4.438 6.427a.739.739 0 0 1-.373-.983z" fill="currentColor"></path></g></svg>
<div class="ellipsis">简历</div>
</a>
</li></ul>
<ul><li class="active">
<a href="/categories/CS/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 4l-2 14.5l-6 2l-6-2L4 4z"></path><path d="M7.5 8h3v8l-2-1"></path><path d="M16.5 8H14a.5.5 0 0 0-.5.5v3a.5.5 0 0 0 .5.5h1.423a.5.5 0 0 1 .495.57L15.5 15.5l-2 .5"></path></g></svg>
<div class="ellipsis">
<span>CS</span>
</div>
</a>
</li><li class="">
<a href="/categories/EQ/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5.636 5.636a9 9 0 0 1 13.397.747L13.414 12l5.619 5.617A9 9 0 1 1 5.636 5.636z"></path><circle cx="11.5" cy="7.5" r="1" fill="currentColor"></circle></g></svg>
<div class="ellipsis">
<span>EQ</span>
</div>
</a>
</li><li class="">
<a href="/categories/Hexo/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 17v1a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-1"></path><path d="M8 16h8"></path><path d="M8.322 12.582l7.956.836"></path><path d="M8.787 9.168l7.826 1.664"></path><path d="M10.096 5.764l7.608 2.472"></path></g></svg>
<div class="ellipsis">
<span>Hexo</span>
</div>
</a>
</li><li class="">
<a href="/categories/%E8%87%AA%E5%AA%92%E4%BD%93/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><path d="M9 12a4 4 0 1 0 4 4V4a5 5 0 0 0 5 5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
<div class="ellipsis">
<span>自媒体</span>
</div>
</a>
</li><li class="">
<a href="/categories/%E8%AF%BB%E4%B9%A6/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20"><g fill="none"><path d="M4 16V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v11a1 1 0 0 1-1 1H5a1 1 0 0 0 1 1h9.5a.5.5 0 0 1 0 1H6a2 2 0 0 1-2-2zM15 4a1 1 0 0 0-1-1H6a1 1 0 0 0-1 1v11h10V4zM7.041 8h.973c.045-.773.192-1.485.42-2.059A3.002 3.002 0 0 0 7.04 8zM6 8.5a4 4 0 1 1 8 0a4 4 0 0 1-8 0zm6.959-.5a3.002 3.002 0 0 0-1.392-2.059c.227.574.374 1.286.419 2.059h.973zm-.973 1c-.045.773-.192 1.486-.42 2.059A3.002 3.002 0 0 0 12.96 9h-.973zm-1.002-1c-.046-.707-.189-1.324-.383-1.778c-.12-.28-.25-.474-.368-.591c-.117-.115-.195-.131-.233-.131c-.038 0-.116.016-.233.13c-.118.118-.248.312-.368.592c-.194.454-.337 1.07-.383 1.778h1.968zM9.016 9c.046.707.189 1.324.383 1.778c.12.28.25.474.368.591c.117.115.195.131.233.131c.038 0 .116-.016.233-.13c.118-.118.248-.313.368-.592c.194-.454.336-1.07.383-1.778H9.016zM8.014 9h-.973c.147.87.668 1.614 1.392 2.059c-.227-.573-.374-1.286-.419-2.059z" fill="currentColor"></path></g></svg>
<div class="ellipsis">
<span>读书</span>
</div>
</a>
</li><li class="">
<a href="/categories/%E8%B4%A2%E7%BB%8F/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"></circle><path d="M14.8 9A2 2 0 0 0 13 8h-2a2 2 0 0 0 0 4h2a2 2 0 0 1 0 4h-2a2 2 0 0 1-1.8-1"></path><path d="M12 6v2m0 8v2"></path></g></svg>
<div class="ellipsis">
<span>财经</span>
</div>
</a>
</li></ul>
</nav>
<script src="/js/118098c2.js"></script>
</div>
<div class="bottom">
<cosy-tooltip id="button-preference" placement="right">
<span slot="content">
<span>偏好</span>
<cosy-short-key></cosy-short-key>
<cosy-short-key>p</cosy-short-key>
</span>
<cosy-icon bordered id="button-about-cosy-theme">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 16 16">
<g fill="none">
<path d="M8 6a2 2 0 1 0 0 4a2 2 0 0 0 0-4zM7 8a1 1 0 1 1 2 0a1 1 0 0 1-2 0zm3.618-3.602a.708.708 0 0 1-.824-.567l-.26-1.416a.354.354 0 0 0-.275-.282a6.072 6.072 0 0 0-2.519 0a.354.354 0 0 0-.275.282l-.259 1.416a.71.71 0 0 1-.936.538l-1.359-.484a.355.355 0 0 0-.382.095c-.569.627-1 1.367-1.262 2.173a.352.352 0 0 0 .108.378l1.102.931a.704.704 0 0 1 0 1.076l-1.102.931a.352.352 0 0 0-.108.378A5.986 5.986 0 0 0 3.53 12.02a.355.355 0 0 0 .382.095l1.36-.484a.708.708 0 0 1 .936.538l.258 1.416c.026.14.135.252.275.281a6.075 6.075 0 0 0 2.52 0a.353.353 0 0 0 .274-.281l.26-1.416a.71.71 0 0 1 .936-.538l1.359.484c.135.048.286.01.382-.095c.569-.627 1-1.367 1.262-2.173a.352.352 0 0 0-.108-.378l-1.102-.931a.703.703 0 0 1 0-1.076l1.102-.931a.352.352 0 0 0 .108-.378A5.985 5.985 0 0 0 12.47 3.98a.355.355 0 0 0-.382-.095l-1.36.484a.71.71 0 0 1-.111.03zm-6.62.58l.937.333a1.71 1.71 0 0 0 2.255-1.3l.177-.97a5.105 5.105 0 0 1 1.265 0l.178.97a1.708 1.708 0 0 0 2.255 1.3L12 4.977c.255.334.467.698.63 1.084l-.754.637a1.704 1.704 0 0 0 0 2.604l.755.637a4.99 4.99 0 0 1-.63 1.084l-.937-.334a1.71 1.71 0 0 0-2.255 1.3l-.178.97a5.099 5.099 0 0 1-1.265 0l-.177-.97a1.708 1.708 0 0 0-2.255-1.3L4 11.023a4.987 4.987 0 0 1-.63-1.084l.754-.638a1.704 1.704 0 0 0 0-2.603l-.755-.637c.164-.386.376-.75.63-1.084z" fill="currentColor"></path>
</g>
</svg>
</cosy-icon>
</cosy-tooltip>
</div>
</aside>
<main>
<link rel="stylesheet" href="/css/9bb9a539.css">
<div class="post-container">
<header>
<div class="left">
<link rel="stylesheet" href="/css/7d333f9e.css">
<nav class="breadcrumb">
<section>
<cosy-tooltip placement="bottom-left">
<span slot="content"><span>首页</span>
<cosy-short-key></cosy-short-key>
<cosy-short-key>H</cosy-short-key>
</span>
<cosy-icon href="/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20">
<g fill="none">
<path d="M8.998 2.388a1.5 1.5 0 0 1 2.005 0l5.5 4.942A1.5 1.5 0 0 1 17 8.445V15.5a1.5 1.5 0 0 1-1.5 1.5H13a1.5 1.5 0 0 1-1.5-1.5V12a.5.5 0 0 0-.5-.5H9a.5.5 0 0 0-.5.5v3.5A1.5 1.5 0 0 1 7 17H4.5A1.5 1.5 0 0 1 3 15.5V8.445c0-.425.18-.83.498-1.115l5.5-4.942zm1.336.744a.5.5 0 0 0-.668 0l-5.5 4.942A.5.5 0 0 0 4 8.445V15.5a.5.5 0 0 0 .5.5H7a.5.5 0 0 0 .5-.5V12A1.5 1.5 0 0 1 9 10.5h2a1.5 1.5 0 0 1 1.5 1.5v3.5a.5.5 0 0 0 .5.5h2.5a.5.5 0 0 0 .5-.5V8.445a.5.5 0 0 0-.166-.371l-5.5-4.942z" fill="currentColor"></path>
</g>
</svg>
</cosy-icon>
</cosy-tooltip>
<svg class="arrow" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20">
<g fill="none">
<path d="M7.733 4.207a.75.75 0 0 1 1.06.026l5.001 5.25a.75.75 0 0 1 0 1.035l-5 5.25a.75.75 0 1 1-1.087-1.034L12.216 10l-4.51-4.734a.75.75 0 0 1 .027-1.06z" fill="currentColor"></path>
</g>
</svg>
<a class="ellipsis" href="/categories/CS/">
CS
</a>
<svg class="arrow" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20">
<g fill="none">
<path d="M7.733 4.207a.75.75 0 0 1 1.06.026l5.001 5.25a.75.75 0 0 1 0 1.035l-5 5.25a.75.75 0 1 1-1.087-1.034L12.216 10l-4.51-4.734a.75.75 0 0 1 .027-1.06z" fill="currentColor"></path>
</g>
</svg>
<span class="ellipsis">
Git
</span>
</section>
</nav>
<script src="/js/31d6cfe0.js"></script>
</div>
<div class="right">
<cosy-tooltip id="toc-show-button" placement="left">
<span slot="content">
<span>显示 / 隐藏 文章目录</span>
<cosy-short-key>]</cosy-short-key>
</span>
<cosy-icon>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20">
<g fill="none">
<path d="M4 4c-1.104-.019-2 .896-2 2v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2H4zM3 6a1 1 0 0 1 1-1h2.995v10H4a1 1 0 0 1-1-1V6zm4.995 9V5h8.004a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H7.995z" fill="currentColor"></path>
</g>
</svg>
</cosy-icon>
</cosy-tooltip>
</div>
</header>
<div class="content">
<main class="cosy-scrollbar">
<div class="article-container">
<!-- 渲染文章内容 -->
<article>
<!-- 文章标题 -->
<h1 class="post-title">Git</h1>
<div class="last-updated">
上次更新: 2023-12-26 12:54:48
</div>
<!-- 文章 -->
<h1 id="GIT-最佳实践"><a href="#GIT-最佳实践" class="headerlink" title="GIT 最佳实践"></a>GIT 最佳实践</h1><p>GIT 本质是一个数据库,用来存代码的</p>
<ul>
<li>工作区一个沙箱环境GIT 不负责管理,你尽管在沙箱里面对文件进行操作</li>
<li>暂存区:<code>工作区</code>文件变动先不急着提交,暂存到一定数量,在提交到版本库</li>
<li>版本库:</li>
</ul>
<blockquote>
<p>!! Linus 永远的神!</p>
</blockquote>
<h2 id="配置用户"><a href="#配置用户" class="headerlink" title="配置用户"></a>配置用户</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">git</span> config <span class="token parameter variable">--global</span> user.name <span class="token string">"mozzie"</span>
<span class="token function">git</span> config <span class="token parameter variable">--global</span> user.email himozzie@foxmail.com<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<h2 id="alias-别名"><a href="#alias-别名" class="headerlink" title="alias 别名"></a>alias 别名</h2><p>解决参数太多,记不住的问题</p>
<blockquote>
<p>!! HEAD -&gt; master HEAD 相当于一个指针,指向当前所在分支</p>
</blockquote>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 查看项目分支图,</span>
<span class="token function">git</span> config <span class="token parameter variable">--global</span> alias.lo <span class="token string">"log --oneline --decorate --graph --all"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<h2 id="git-文件结构"><a href="#git-文件结构" class="headerlink" title=".git 文件结构"></a>.git 文件结构</h2><ul>
<li>hooks提交代码前检查代码格式……</li>
<li>info包含一个排除性文件</li>
<li>logs保存日志信息不太需要</li>
<li><code>objects</code>:相当于数据库,存储所有数据内容</li>
<li><code>refs</code>:存放提交对象指针,管理分支的</li>
<li>config配置文件</li>
<li>description仓库描述信息</li>
<li><code>HEAD</code>:指示目前被检出的分支</li>
<li><code>index</code>:文件保存暂存区信息</li>
</ul>
<h2 id="修改远程仓库"><a href="#修改远程仓库" class="headerlink" title="修改远程仓库"></a>修改远程仓库</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># way 1</span>
<span class="token function">git</span> remote set-url origin <span class="token punctuation">[</span>url<span class="token punctuation">]</span>
<span class="token comment"># way 2</span>
<span class="token function">git</span> remote <span class="token function">rm</span> origin
<span class="token function">git</span> remote <span class="token function">add</span> origin <span class="token punctuation">[</span>url<span class="token punctuation">]</span>
<span class="token comment"># way3</span>
修改 config 文件<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="高层命令"><a href="#高层命令" class="headerlink" title="高层命令"></a>高层命令</h2><h3 id="初始化仓库"><a href="#初始化仓库" class="headerlink" title="初始化仓库"></a>初始化仓库</h3><p><code>git init</code></p>
<h3 id="修改添加到暂存区"><a href="#修改添加到暂存区" class="headerlink" title="修改添加到暂存区"></a>修改添加到暂存区</h3><p><code>git add ./</code>,相当于如下操作:</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 有多少文件改动,就执行多少次</span>
<span class="token function">git</span> hash-object <span class="token parameter variable">-w</span> 文件名
<span class="token function">git</span> update-index<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<blockquote>
<p>!! git add .&#x2F; 先把工作区生成 git 对象,放到版本库,然后再放到暂存区</p>
</blockquote>
<h3 id="暂存区提交到版本库"><a href="#暂存区提交到版本库" class="headerlink" title="暂存区提交到版本库"></a>暂存区提交到版本库</h3><p><code>git commit -m &#39;comment&#39;</code>,相当于如下操作:</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">git</span> write-tree
<span class="token function">git</span> commit-tree<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<p>也可以跳过暂存区提交,<code>git commit -a -m </code></p>
<h3 id="查看哪些修改没有暂存"><a href="#查看哪些修改没有暂存" class="headerlink" title="查看哪些修改没有暂存"></a>查看哪些修改没有暂存</h3><p><code>git diff</code>:没有暂存</p>
<p><code>git diff --staged</code>:查看哪些修改以及被暂存了,但没有提交</p>
<h3 id="查看提交历史记录"><a href="#查看提交历史记录" class="headerlink" title="查看提交历史记录"></a>查看提交历史记录</h3><p><code>git log --oneline</code>,打印出<code>hash值</code>是提交对象</p>
<h2 id="分支"><a href="#分支" class="headerlink" title="分支"></a>分支</h2><p>本质是一个<code>提交对象</code>,每次<code>git branch name</code>中的<code>name</code>,指针<code>HEAD</code>,就会根据<code>name</code>指向提交对象</p>
<p>如果要开发新功能,就新建一个<code>分支A</code>,写完再合<code>master</code>分支,正常来说<code>master</code>分支不会轻易给修改权限。</p>
<p>如果另一个新功能,和<code>分支A</code>同级、并行的,那就<code>切到master</code>分支,在<code>master</code>分支基础上,开<code>分支B</code>,进行新功能开发</p>
<blockquote>
<p>一般来说master 分支没有权限,需要自己重新写开一个分支,分支名用 nickname</p>
</blockquote>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">C1 master
<span class="token operator">|</span>——C2——C3——C4 mozzie<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<h3 id="分支列表"><a href="#分支列表" class="headerlink" title="分支列表"></a>分支列表</h3><p><code>git branch</code></p>
<h3 id="创建分支"><a href="#创建分支" class="headerlink" title="创建分支"></a>创建分支</h3><p><code>git branch 分支名</code>,并不会自动切换到分支</p>
<h3 id="切换分支"><a href="#切换分支" class="headerlink" title="切换分支"></a>切换分支</h3><blockquote>
<p>!! 最佳实践每次切换分之前git status 查一下,当前分支一定要是干净的</p>
</blockquote>
<p><code>git checkout 分支名</code></p>
<h3 id="合并分支"><a href="#合并分支" class="headerlink" title="合并分支"></a>合并分支</h3><blockquote>
<p>!! 做任何事情,确保做完了,再合并到 master 分支</p>
</blockquote>
<p>场景:需要增加功能<code>feat:#53</code></p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># HEAD -> master新开一个分支</span>
<span class="token function">git</span> checkout <span class="token parameter variable">-b</span> <span class="token string">'feat53'</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<p>突然发现 bug需要修复<code>bug:#52</code></p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># HEAD -> feat53先提交#53分支的工作</span>
<span class="token function">git</span> commit <span class="token parameter variable">-a</span> <span class="token parameter variable">-m</span> <span class="token string">'feat53 完成50%'</span>
<span class="token comment"># 切回 master 分支</span>
<span class="token function">git</span> checkout master
<span class="token comment"># HEAD -> master创建 issue52 分支</span>
<span class="token function">git</span> checkout <span class="token parameter variable">-b</span> <span class="token string">'issue52'</span>
<span class="token comment"># 改完了issue52</span>
<span class="token function">git</span> commit <span class="token parameter variable">-a</span> <span class="token parameter variable">-m</span> <span class="token string">'fix:issue52'</span>
<span class="token comment"># HEAD -> master</span>
<span class="token function">git</span> checkout master
<span class="token comment"># 合</span>
<span class="token function">git</span> merge issue52
<span class="token comment"># 删除 issue52分支(hash还在)</span>
<span class="token function">git</span> branch <span class="token parameter variable">-d</span> issue52<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<blockquote>
<p>此时,由于<code>issue52</code>是在之前的 master 分支上生成的,故而<code>feat53</code>的分支仍然存在<code>issue52</code>的 bug所以有可能存在冲突需要手动解决</p>
</blockquote>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># HEAD -> master</span>
<span class="token function">git</span> merge feat53
<span class="token comment"># 此处省略解决冲突</span>
<span class="token function">git</span> <span class="token function">add</span> ./
<span class="token function">git</span> commit <span class="token parameter variable">-m</span> <span class="token string">'fix:merge conflict'</span>
<span class="token comment"># 删除 feat53</span>
<span class="token function">git</span> branch <span class="token parameter variable">-d</span> feat53<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h3 id="删除分支"><a href="#删除分支" class="headerlink" title="删除分支"></a>删除分支</h3><p>查看哪些分支合并到当前分支,<code>git branch --merged</code>,这个列表中分支名字前没有*号的分支通常可以使用<code>git branch -d 分支名</code>删掉</p>
<p><code>git branch -D 分支名</code>,强制删除</p>
<h3 id="新建分支并指向指定提交对象"><a href="#新建分支并指向指定提交对象" class="headerlink" title="新建分支并指向指定提交对象"></a>新建分支并指向指定提交对象</h3><p><code>git branch name commitHash</code>,例<code>git log --oneline</code>如下:</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">* hasfh2asd <span class="token number">1</span>.txt
* 1shfd2zsw <span class="token number">2</span>.txt
* 67rf73has <span class="token number">3</span>.txt
* 03uhr4rug <span class="token number">4</span>.txt<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>
<p>输入<code>git branch CCC 03uhr4rug</code>,那么会创建一个名为<code>CCC</code>的分支,并且<code>CCC</code>分支有<code>4.txt</code></p>
<blockquote>
<p>通常想看原来的某个版本的代码,就可以这样操作,看完,把这个分支删了</p>
</blockquote>
<h3 id="远程分支"><a href="#远程分支" class="headerlink" title="远程分支"></a>远程分支</h3><blockquote>
<p><code>git clone</code>下来的分支,默认就会建立一个<code>远程跟踪分支</code>(同步关系),例如 master 分支</p>
</blockquote>
<ul>
<li>本地分支</li>
</ul>
<p>场景一:如果想公开一个<code>share</code>分支 ,与他人共同写作:</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 过程中会生成生成一个远程跟踪分支 origin/share</span>
<span class="token function">git</span> push origin share<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<p>场景二:创建一个本地分支<code>b1</code>,直接跟踪远程分支<code>orgin/b1</code></p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">git</span> checkout <span class="token parameter variable">-b</span> <span class="token string">'b1'</span> <span class="token string">'origin/b1'</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>场景三:已存在一个本地分支<code>dev</code>,改成远程跟踪分支</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># HEAD -> dev建立 本地分支 dev 与 远程分支 origin/dev 关系</span>
<span class="token function">git</span> branch <span class="token parameter variable">-u</span> origin/dev
<span class="token comment"># 这样就可以直接</span>
<span class="token function">git</span> push / <span class="token function">git</span> pull<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>
<ul>
<li>远程分支</li>
</ul>
<p>查看远程分支:<code>git remote -v</code></p>
<p>查看当前本地分支的远程跟踪分支:<code>git branch -vv</code></p>
<h2 id="远程分支删除-本地更新-prune"><a href="#远程分支删除-本地更新-prune" class="headerlink" title="远程分支删除, 本地更新 prune"></a>远程分支删除, 本地更新 prune</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 不加 --prune和 fetch 等价, 远程被删除的分支不会同步删除本地origin的分支</span>
<span class="token function">git</span> remote update origin <span class="token parameter variable">--prune</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<h1 id="提交规范"><a href="#提交规范" class="headerlink" title="提交规范"></a>提交规范</h1><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">type<span class="token punctuation">(</span>scope<span class="token punctuation">)</span>: subject
<span class="token comment"># 例如</span>
feat<span class="token punctuation">(</span>miniprogram<span class="token punctuation">)</span>: 增加了小程序模板消息相关功能<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<p>通常<code>type</code>有如下:</p>
<ul>
<li>feat - 新功能 feature</li>
<li>fix - 修复 bug</li>
<li>docs - 文档注释</li>
<li>style - 代码格式(不影响代码运行的变动)</li>
<li>refactor - 重构、优化(既不增加新功能,也不是修复 bug)</li>
<li>perf - 性能优化</li>
<li>test - 增加测试</li>
<li>chore - 构建过程或辅助工具的变动</li>
<li>revert - 回退</li>
<li>build - 打包</li>
</ul>
<h2 id="自动生成-Change-log"><a href="#自动生成-Change-log" class="headerlink" title="自动生成 Change log"></a>自动生成 Change log</h2><p>原理:利用 <code>child_process</code>获取 <code>git log</code>内容,处理字符串</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">const</span> execSync <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"child_process"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>execSync<span class="token punctuation">;</span> <span class="token comment">//同步子进程</span>
<span class="token keyword">const</span> fs <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"fs"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> process <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"process"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> path <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"path"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> inquirer <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"inquirer"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> dayjs <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"dayjs"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> axios <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"axios"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// env</span>
<span class="token keyword">const</span> isForCommanHuman <span class="token operator">=</span> process<span class="token punctuation">.</span>argv<span class="token punctuation">.</span><span class="token function">includes</span><span class="token punctuation">(</span><span class="token string">"--common"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// changelog.md生成路径</span>
<span class="token keyword">const</span> outputpath <span class="token operator">=</span> path<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span>process<span class="token punctuation">.</span><span class="token function">cwd</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">"./changelog.md"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 非空检测</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>fs<span class="token punctuation">.</span><span class="token function">existsSync</span><span class="token punctuation">(</span>outputpath<span class="token punctuation">)</span><span class="token punctuation">)</span> fs<span class="token punctuation">.</span><span class="token function">writeFile</span><span class="token punctuation">(</span>outputpath<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">err</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 华丽的gitlog日志</span>
<span class="token keyword">const</span> <span class="token function-variable function">perfectGitLog</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">startTime<span class="token punctuation">,</span> endTime</span><span class="token punctuation">)</span> <span class="token operator">=></span>
isForCommanHuman
<span class="token operator">?</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">git log --since="</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span>startTime<span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">" --until="</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span>endTime<span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">" --no-merges --pretty=format:"%cr %C(cyan)%s"</span><span class="token template-punctuation string">`</span></span>
<span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">git log --since="</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span>startTime<span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">" --until="</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span>endTime<span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">" --no-merges --pretty=format:"%C(yellow)%h %C(green)%cn %C(redz)(%cr:%ci) %C(cyan)%s"</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>
<span class="token keyword">const</span> wxrobotHook <span class="token operator">=</span>
<span class="token string">"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=be4d4473-c290-4ddd-a089-41df3ed1d601"</span><span class="token punctuation">;</span>
<span class="token comment">// 当前时间</span>
<span class="token keyword">const</span> now <span class="token operator">=</span> Date<span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 2周前</span>
<span class="token keyword">const</span> weeks_2_ago <span class="token operator">=</span> now <span class="token operator">-</span> <span class="token number">14</span> <span class="token operator">*</span> <span class="token number">24</span> <span class="token operator">*</span> <span class="token number">60</span> <span class="token operator">*</span> <span class="token number">60</span> <span class="token operator">*</span> <span class="token number">1000</span><span class="token punctuation">;</span>
inquirer
<span class="token punctuation">.</span><span class="token function">prompt</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
<span class="token punctuation">&#123;</span>
<span class="token literal-property property">type</span><span class="token operator">:</span> <span class="token string">"input"</span><span class="token punctuation">,</span>
<span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">"startDate"</span><span class="token punctuation">,</span>
<span class="token literal-property property">message</span><span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">起始时间,默认13天前 \n</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span>
<span class="token keyword">default</span><span class="token operator">:</span> <span class="token function">dayjs</span><span class="token punctuation">(</span>weeks_2_ago<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">"YYYY.MM.DD"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token function-variable function">validate</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">val</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">\d&#123;4&#125;.\d&#123;2&#125;.\d&#123;2&#125;</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>val<span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
<span class="token punctuation">&#123;</span>
<span class="token literal-property property">type</span><span class="token operator">:</span> <span class="token string">"input"</span><span class="token punctuation">,</span>
<span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">"endDate"</span><span class="token punctuation">,</span>
<span class="token literal-property property">message</span><span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">结束时间,默认今天 \n</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span>
<span class="token keyword">default</span><span class="token operator">:</span> <span class="token function">dayjs</span><span class="token punctuation">(</span>now<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">"YYYY.MM.DD"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token function-variable function">validate</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">val</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">\d&#123;4&#125;.\d&#123;2&#125;.\d&#123;2&#125;</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>val<span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
<span class="token punctuation">&#123;</span>
<span class="token literal-property property">type</span><span class="token operator">:</span> <span class="token string">"rawlist"</span><span class="token punctuation">,</span>
<span class="token literal-property property">message</span><span class="token operator">:</span> <span class="token string">"是否通知到微信机器人:"</span><span class="token punctuation">,</span>
<span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">"notifyWxrobot"</span><span class="token punctuation">,</span>
<span class="token literal-property property">choices</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"Y"</span><span class="token punctuation">,</span> <span class="token string">"N"</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">answers</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">&#123;</span>
<span class="token keyword">const</span> <span class="token punctuation">&#123;</span> startDate<span class="token punctuation">,</span> endDate<span class="token punctuation">,</span> notifyWxrobot <span class="token punctuation">&#125;</span> <span class="token operator">=</span> answers<span class="token punctuation">;</span>
<span class="token keyword">const</span> rowTemplate <span class="token operator">=</span> <span class="token function">perfectGitLog</span><span class="token punctuation">(</span>startDate<span class="token punctuation">,</span> endDate<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> fmt <span class="token operator">=</span> <span class="token function">execSync</span><span class="token punctuation">(</span>rowTemplate<span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">feat: </span><span class="token regex-delimiter">/</span><span class="token regex-flags">gi</span></span><span class="token punctuation">,</span> <span class="token string">"✅: "</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">fix: </span><span class="token regex-delimiter">/</span><span class="token regex-flags">gi</span></span><span class="token punctuation">,</span> <span class="token string">"🐛: "</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">chore: </span><span class="token regex-delimiter">/</span><span class="token regex-flags">gi</span></span><span class="token punctuation">,</span> <span class="token string">"🎨: "</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">perf: </span><span class="token regex-delimiter">/</span><span class="token regex-flags">gi</span></span><span class="token punctuation">,</span> <span class="token string">"⚡: "</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">docs: </span><span class="token regex-delimiter">/</span><span class="token regex-flags">gi</span></span><span class="token punctuation">,</span> <span class="token string">"📝: "</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">refactor: </span><span class="token regex-delimiter">/</span><span class="token regex-flags">gi</span></span><span class="token punctuation">,</span> <span class="token string">"🔨: "</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">anno: </span><span class="token regex-delimiter">/</span><span class="token regex-flags">gi</span></span><span class="token punctuation">,</span> <span class="token string">"🔖: "</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">style: </span><span class="token regex-delimiter">/</span><span class="token regex-flags">gi</span></span><span class="token punctuation">,</span> <span class="token string">"👷: "</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
fs<span class="token punctuation">.</span><span class="token function">writeFileSync</span><span class="token punctuation">(</span>outputpath<span class="token punctuation">,</span> fmt<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">err</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 通知微信群聊机器人</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>notifyWxrobot <span class="token operator">===</span> <span class="token string">"Y"</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
axios<span class="token punctuation">.</span><span class="token function">post</span><span class="token punctuation">(</span>wxrobotHook<span class="token punctuation">,</span> <span class="token punctuation">&#123;</span>
<span class="token literal-property property">msgtype</span><span class="token operator">:</span> <span class="token string">"markdown"</span><span class="token punctuation">,</span>
<span class="token literal-property property">markdown</span><span class="token operator">:</span> <span class="token punctuation">&#123;</span>
<span class="token literal-property property">content</span><span class="token operator">:</span> fmt<span class="token punctuation">,</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">error</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">&#123;</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>error<span class="token punctuation">.</span>isTtyError<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
<span class="token comment">// Prompt couldn't be rendered in the current environment</span>
<span class="token punctuation">&#125;</span> <span class="token keyword">else</span> <span class="token punctuation">&#123;</span>
<span class="token comment">// Something else went wrong</span>
<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="使用-husky-eslint-规范提交"><a href="#使用-husky-eslint-规范提交" class="headerlink" title="使用 husky+eslint 规范提交"></a>使用 husky+eslint 规范提交</h2><blockquote>
<p>需要配合 eslint</p>
</blockquote>
<p><code>git init</code>后,<code>yarn add husky</code>,在<code>package.json</code>配置</p>
<pre class="line-numbers language-json" data-language="json"><code class="language-json"><span class="token punctuation">&#123;</span>
<span class="token property">"husky"</span><span class="token operator">:</span> <span class="token punctuation">&#123;</span>
<span class="token property">"hooks"</span><span class="token operator">:</span> <span class="token punctuation">&#123;</span>
<span class="token property">"pre-commit"</span><span class="token operator">:</span> <span class="token string">"npm run lint"</span>
<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="生成-ssh-key"><a href="#生成-ssh-key" class="headerlink" title="生成 ssh key"></a>生成 ssh key</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">ssh-keygen <span class="token parameter variable">-t</span> rsa <span class="token parameter variable">-C</span> <span class="token string">"himozzie@foxmail.com"</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<h2 id="查看-ssh-公钥"><a href="#查看-ssh-公钥" class="headerlink" title="查看 ssh 公钥"></a>查看 ssh 公钥</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">cat</span> ~/.ssh/id_rsa.pub<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<h1 id="git-代理"><a href="#git-代理" class="headerlink" title="git 代理"></a>git 代理</h1><blockquote>
<p>前提条件是开了扶墙工具</p>
</blockquote>
<p>git clone 拉取方式选择 http&#x2F;https(默认会让你输入账号密码,比较蛋疼),不要选择 ssl 拉取</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">git</span> config <span class="token parameter variable">--global</span> http.proxy <span class="token string">'http://127.0.0.1:1081'</span>
<span class="token function">git</span> config <span class="token parameter variable">--global</span> https.proxy <span class="token string">'https://127.0.0.1:1081'</span>
<span class="token comment"># 清除</span>
<span class="token function">git</span> config <span class="token parameter variable">--global</span> <span class="token parameter variable">--unset</span> http.proxy
<span class="token function">git</span> config <span class="token parameter variable">--global</span> <span class="token parameter variable">--unset</span> https.proxy<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h1 id="终端临时代理"><a href="#终端临时代理" class="headerlink" title="终端临时代理"></a>终端临时代理</h1><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># cmd临时代理方案cmd窗口关闭则代理失效</span>
<span class="token builtin class-name">set</span> <span class="token assign-left variable">http_proxy</span><span class="token operator">=</span>http://127.0.0.1:50015
<span class="token builtin class-name">set</span> <span class="token assign-left variable">https_proxy</span><span class="token operator">=</span>http://127.0.0.1:50015<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<h1 id="git-钩子-hooks"><a href="#git-钩子-hooks" class="headerlink" title="git 钩子(hooks)"></a>git 钩子(hooks)</h1><p>原理:项目 git push 到远程仓库,远程仓库的钩子 post 通知 www&#x2F;wwwroot 下的站点 pull 远程仓库</p>
<blockquote>
<p>git 钩子需要 git 服务和 pull 在同一环境中</p>
</blockquote>
<ul>
<li>创建远程仓库,配置钩子,git post-receive 钩子</li>
</ul>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token shebang important">#!/bin/bash</span>
<span class="token builtin class-name">unset</span> <span class="token variable"><span class="token variable">$(</span><span class="token function">git</span> rev-parse --local-env-vars<span class="token variable">)</span></span><span class="token punctuation">;</span>
<span class="token comment"># post-receive接收到pull指令后,执行bash命令</span>
<span class="token builtin class-name">cd</span> /www/wwwroot/doc.mozzie.cn/ <span class="token operator">&amp;&amp;</span> <span class="token function">git</span> pull origin master<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>
<blockquote>
<p>web 目录下 doc.mozzie.cn 是网站目录,本地项目编译打包后,直接 git push 的目录</p>
</blockquote>
<h2 id="web-钩子"><a href="#web-钩子" class="headerlink" title="web 钩子"></a>web 钩子</h2><p>待耍</p>
<h1 id="项目"><a href="#项目" class="headerlink" title="项目"></a>项目</h1><h2 id="统计项目代码行数"><a href="#统计项目代码行数" class="headerlink" title="统计项目代码行数"></a>统计项目代码行数</h2><p>统计所有人代码增删量,拷贝如下命令, git bash 终端git 项目某分支下执行</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">git</span> log <span class="token parameter variable">--format</span><span class="token operator">=</span><span class="token string">'%aN'</span> <span class="token operator">|</span> <span class="token function">sort</span> <span class="token parameter variable">-u</span> <span class="token operator">|</span> <span class="token keyword">while</span> <span class="token builtin class-name">read</span> name<span class="token punctuation">;</span> <span class="token keyword">do</span> <span class="token builtin class-name">echo</span> <span class="token parameter variable">-en</span> <span class="token string">"<span class="token variable">$name</span><span class="token entity" title="\t">\t</span>"</span><span class="token punctuation">;</span> <span class="token function">git</span> log <span class="token parameter variable">--author</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$name</span>"</span> <span class="token parameter variable">--pretty</span><span class="token operator">=</span>tformat: <span class="token parameter variable">--numstat</span> <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'&#123; add += $1; subs += $2; loc += $1 - $2 &#125; END &#123; printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc &#125;'</span> -<span class="token punctuation">;</span> <span class="token keyword">done</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<h2 id="统计制定提交者代码量"><a href="#统计制定提交者代码量" class="headerlink" title="统计制定提交者代码量"></a>统计制定提交者代码量</h2><p>替换<code>username</code>为提交者的名称</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">git</span> log <span class="token parameter variable">--author</span><span class="token operator">=</span><span class="token string">"username"</span> <span class="token parameter variable">--pretty</span><span class="token operator">=</span>tformat: <span class="token parameter variable">--numstat</span> <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'&#123; add += $1; subs += $2; loc += $1 - $2 &#125; END &#123; printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc &#125;'</span> -<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<h1 id="搭建-gogs"><a href="#搭建-gogs" class="headerlink" title="搭建 gogs"></a>搭建 gogs</h1><p>gogs 官网下载,压缩包解压到<code>www/wwwroot/</code></p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token builtin class-name">cd</span> /www/wwwroot/gogs
<span class="token comment"># 启服务,默认3000的端口被占用则 ./gogs web -port 3001</span>
./gogs web<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<p>浏览器访问<code>http://yourip:3000/install</code>,注意服务器安全组放行 3000 端口</p>
<ul>
<li>为 gogs 添加 mysql 数据库</li>
<li>配置 mysql</li>
<li>配置 gogs 相关信息</li>
<li>配置其他信息</li>
</ul>
<p>停掉<code>./gogs web</code></p>
<p>在刚安装的 gogs 路径下,找到<code>/gogs/scripts/systemd/gogs.service</code> 文件复制一份</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token assign-left variable">User</span><span class="token operator">=</span>root
<span class="token assign-left variable">Group</span><span class="token operator">=</span>root
<span class="token assign-left variable">WorkingDirectory</span><span class="token operator">=</span>/www/wwwroot/git.mozzie.cn
<span class="token assign-left variable">ExecStart</span><span class="token operator">=</span>/www/wwwroot/git.mozzie.cn/gogs web
<span class="token assign-left variable">Restart</span><span class="token operator">=</span>always
<span class="token assign-left variable">Environment</span><span class="token operator">=</span><span class="token environment constant">USER</span><span class="token operator">=</span>root <span class="token assign-left variable"><span class="token environment constant">HOME</span></span><span class="token operator">=</span>/www/wwwroot/git.mozzie.cn<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>将修改好的<code>gogs.service</code>文件上传到<code>/etc/systemd/system</code>下,并执行以下命令来激活 gogs</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">sudo</span> systemctl <span class="token builtin class-name">enable</span> gogs
<span class="token comment"># 启动gogs</span>
<span class="token function">sudo</span> systemctl start gogs<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<p><code>/gogs/custom/conf/app.ini</code>,修改该文件可以自定义配置,安装步骤填错了,可以这里修改,重启 gogs 服务即可</p>
<h2 id="配置-gogs-GIT-钩子"><a href="#配置-gogs-GIT-钩子" class="headerlink" title="配置 gogs GIT 钩子"></a>配置 gogs GIT 钩子</h2><p>场景:以 Gogs 为例,先 git push <code>A项目</code> 到远程仓库 <code>REPO</code>,服务端 web 目录<code>webB</code>文件夹触发钩子执行 git pull</p>
<p>1、gogs 初始化一个仓库<code>REPO</code>,仓库设置&#x3D;&gt;管理 GIT 钩子&#x3D;&gt;post-receive填入</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token shebang important">#!/bin/sh</span>
<span class="token builtin class-name">export</span> <span class="token assign-left variable">GIT_WORK_TREE</span><span class="token operator">=</span>/www/wwwroot/webB
<span class="token builtin class-name">export</span> <span class="token assign-left variable">GIT_DIR</span><span class="token operator">=</span><span class="token variable">$&#123;GIT_WORK_TREE&#125;</span>/.git
<span class="token builtin class-name">cd</span> <span class="token variable">$&#123;GIT_WORK_TREE&#125;</span>
<span class="token function">git</span> pull<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>2、利用 ssh 工具登录服务器</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">ssh</span> root@mozzie.cn<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>3、生成 ssh key</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">ssh-keygen <span class="token parameter variable">-t</span> rsa <span class="token parameter variable">-C</span> <span class="token string">"himozzie@foxmail.com"</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>4、配置公钥到 gogs</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">cat</span> ~/.ssh/id_rsa.pub<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>把打印出的公钥,配置到 ssh 密钥</p>
<p>5、最后一步</p>
<p>配置好服务端的公钥后,就可以无需用户名密码,<code>cd /webB</code>目录下,执行<code>git pull</code>,此后每次<code>git push A项目</code>,服务端都会触发<code>GIT钩子</code>,自动从<code>REPO</code>拉取最新的仓库文件</p>
<div class="post-tags">
<!-- 文章tags -->
</div>
<p class="motto">重拾纯粹的写作</p>
</article>
<!-- 评论 -->
<div id="vcomments"></div>
</div>
</main>
<!-- toc -->
<cosy-drag-box id="toc-drag-box" trigger="left" min-width="220" uid="toc-box">
<div class="meta-container">
<div class="toc-wrapper cosy-scrollbar">
<p class="catalog">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24">
<g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 6h16"></path>
<path d="M4 12h16"></path>
<path d="M4 18h12"></path>
</g>
</svg>
<span>目录</span>
</p>
<!-- 文章toc -->
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#GIT-%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5"><span class="toc-number">1.</span> <span class="toc-text">GIT 最佳实践</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E7%94%A8%E6%88%B7"><span class="toc-number">1.1.</span> <span class="toc-text">配置用户</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#alias-%E5%88%AB%E5%90%8D"><span class="toc-number">1.2.</span> <span class="toc-text">alias 别名</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#git-%E6%96%87%E4%BB%B6%E7%BB%93%E6%9E%84"><span class="toc-number">1.3.</span> <span class="toc-text">.git 文件结构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93"><span class="toc-number">1.4.</span> <span class="toc-text">修改远程仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%AB%98%E5%B1%82%E5%91%BD%E4%BB%A4"><span class="toc-number">1.5.</span> <span class="toc-text">高层命令</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BB%93%E5%BA%93"><span class="toc-number">1.5.1.</span> <span class="toc-text">初始化仓库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%B7%BB%E5%8A%A0%E5%88%B0%E6%9A%82%E5%AD%98%E5%8C%BA"><span class="toc-number">1.5.2.</span> <span class="toc-text">修改添加到暂存区</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9A%82%E5%AD%98%E5%8C%BA%E6%8F%90%E4%BA%A4%E5%88%B0%E7%89%88%E6%9C%AC%E5%BA%93"><span class="toc-number">1.5.3.</span> <span class="toc-text">暂存区提交到版本库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E5%93%AA%E4%BA%9B%E4%BF%AE%E6%94%B9%E6%B2%A1%E6%9C%89%E6%9A%82%E5%AD%98"><span class="toc-number">1.5.4.</span> <span class="toc-text">查看哪些修改没有暂存</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95"><span class="toc-number">1.5.5.</span> <span class="toc-text">查看提交历史记录</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%86%E6%94%AF"><span class="toc-number">1.6.</span> <span class="toc-text">分支</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%94%AF%E5%88%97%E8%A1%A8"><span class="toc-number">1.6.1.</span> <span class="toc-text">分支列表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF"><span class="toc-number">1.6.2.</span> <span class="toc-text">创建分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%87%E6%8D%A2%E5%88%86%E6%94%AF"><span class="toc-number">1.6.3.</span> <span class="toc-text">切换分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%88%E5%B9%B6%E5%88%86%E6%94%AF"><span class="toc-number">1.6.4.</span> <span class="toc-text">合并分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E5%88%86%E6%94%AF"><span class="toc-number">1.6.5.</span> <span class="toc-text">删除分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%B0%E5%BB%BA%E5%88%86%E6%94%AF%E5%B9%B6%E6%8C%87%E5%90%91%E6%8C%87%E5%AE%9A%E6%8F%90%E4%BA%A4%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.6.6.</span> <span class="toc-text">新建分支并指向指定提交对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF"><span class="toc-number">1.6.7.</span> <span class="toc-text">远程分支</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF%E5%88%A0%E9%99%A4-%E6%9C%AC%E5%9C%B0%E6%9B%B4%E6%96%B0-%E2%80%93prune"><span class="toc-number">1.7.</span> <span class="toc-text">远程分支删除, 本地更新 prune</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8F%90%E4%BA%A4%E8%A7%84%E8%8C%83"><span class="toc-number">2.</span> <span class="toc-text">提交规范</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90-Change-log"><span class="toc-number">2.1.</span> <span class="toc-text">自动生成 Change log</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8-husky-eslint-%E8%A7%84%E8%8C%83%E6%8F%90%E4%BA%A4"><span class="toc-number">2.2.</span> <span class="toc-text">使用 husky+eslint 规范提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%94%9F%E6%88%90-ssh-key"><span class="toc-number">2.3.</span> <span class="toc-text">生成 ssh key</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B-ssh-%E5%85%AC%E9%92%A5"><span class="toc-number">2.4.</span> <span class="toc-text">查看 ssh 公钥</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#git-%E4%BB%A3%E7%90%86"><span class="toc-number">3.</span> <span class="toc-text">git 代理</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%BB%88%E7%AB%AF%E4%B8%B4%E6%97%B6%E4%BB%A3%E7%90%86"><span class="toc-number">4.</span> <span class="toc-text">终端临时代理</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#git-%E9%92%A9%E5%AD%90-hooks"><span class="toc-number">5.</span> <span class="toc-text">git 钩子(hooks)</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#web-%E9%92%A9%E5%AD%90"><span class="toc-number">5.1.</span> <span class="toc-text">web 钩子</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE"><span class="toc-number">6.</span> <span class="toc-text">项目</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%9F%E8%AE%A1%E9%A1%B9%E7%9B%AE%E4%BB%A3%E7%A0%81%E8%A1%8C%E6%95%B0"><span class="toc-number">6.1.</span> <span class="toc-text">统计项目代码行数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%9F%E8%AE%A1%E5%88%B6%E5%AE%9A%E6%8F%90%E4%BA%A4%E8%80%85%E4%BB%A3%E7%A0%81%E9%87%8F"><span class="toc-number">6.2.</span> <span class="toc-text">统计制定提交者代码量</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%90%AD%E5%BB%BA-gogs"><span class="toc-number">7.</span> <span class="toc-text">搭建 gogs</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE-gogs-GIT-%E9%92%A9%E5%AD%90"><span class="toc-number">7.1.</span> <span class="toc-text">配置 gogs GIT 钩子</span></a></li></ol></li></ol>
</div>
</div>
</cosy-drag-box>
</div>
</div>
<script>
window.page = {
use: ''
}
window.katex = {
enable: "",
jsCdn: "//cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.js",
cssCdn: "//cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.css"
}
window.mermaid = {
enable: "",
theme: "",
cdn: "//cdn.jsdelivr.net/npm/mermaid@10.4.0/dist/mermaid.min.js",
}
window.valine = {
enable: "",
appId: 'TisMit6uhflounFqAN3ZGjgq-MdYXbMMI',
appKey: 'CdjirjYdz07U5i62ElsJvXUh',
avatar: 'monsterid',
cdn: '//unpkg.com/valine@latest/dist/Valine.min.js',
serverURLs: '//tismit6u.api.lncldglobal.com'
};
</script>
<script src="/js/0af3d6bb.js"></script>
</main>
</body>
<script>
window.theme = {
color: 'hsl(238,50%,56%)'
}
</script>
<script src="/js/9c8197f9.js"></script>
</html>