2023-11-06 16:05:27 +08:00
<!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" >
2023-12-26 10:56:25 +08:00
< link rel = "canonical" href = "https://mozzie.cn/2023/11/06/clqlr9qre000j6gz3gj724hui/" >
2023-11-06 16:05:27 +08:00
< 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>' >
2023-12-26 10:56:25 +08:00
< link rel = "stylesheet" href = "/css/b2495cef.css" >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< 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 >
2023-11-06 16:05:27 +08:00
< body id = "app" >
2023-12-25 16:39:03 +08:00
< aside id = "aside-box" class = "left-aside" >
< div class = "header" >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< link rel = "stylesheet" href = "/css/61875ce9.css" >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< div class = "profile" >
< a class = "badge" href = "/" >
< span > Hi< / span >
2023-11-06 16:05:27 +08:00
< span > Mozzie< / span >
< / a >
2023-12-25 16:39:03 +08:00
< 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 >
2023-11-06 16:05:27 +08:00
< / div >
2023-12-25 16:39:03 +08:00
< script src = "/js/a66044b6.js" > < / script >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< cosy-search id = "post-search" placeholder = "搜索" >
< div slot = "short-key" >
< cosy-short-key > ⌘< / cosy-short-key >
< cosy-short-key > K< / cosy-short-key >
2023-11-06 16:05:27 +08:00
< / div >
2023-12-25 16:39:03 +08:00
< / cosy-search >
2023-11-06 16:05:27 +08:00
< script >
window.algolia = {
appId: "5DTW808BZ8",
SearchOnlyAPIKey: "27845b245efc8a2853cc0bdc7366ea26"
}
< / script >
2023-12-25 16:39:03 +08:00
< script src = "/js/5f00f278.js" > < / script >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< / div >
< div class = "aside-category" >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< link rel = "stylesheet" href = "/css/db04a759.css" >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< nav class = "category-nav cosy-scrollbar" >
< ul > < li data-path = "archives" >
2023-11-10 13:44:10 +08:00
< a href = "/archives" >
2023-12-25 16:39:03 +08:00
< 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 >
2023-11-10 13:44:10 +08:00
< / li > < / ul >
< ul > < 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 >
2023-11-10 13:51:34 +08:00
< div class = "ellipsis" >
< span > EQ< / span >
< / div >
2023-11-10 13:44:10 +08:00
< / a >
< / li > < li class = "" >
< a href = "/categories/Finance/" >
2023-12-26 10:56:25 +08:00
< 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 1v11h10V4zm-8 7.25c0-.076.012-.149.031-.218c.145.11.297.21.453.3A5.109 5.109 0 0 0 10 12c.982 0 1.863-.293 2.516-.669c.156-.09.308-.19.453-.299c.02.07.031.142.031.218c0 .3-.182.55-.33.71a2.798 2.798 0 0 1-.653.505c-.52.299-1.23.535-2.017.535a4.109 4.109 0 0 1-2.017-.535a2.8 2.8 0 0 1-.654-.504C7.182 11.8 7 11.55 7 11.25zm.031-2.218A.788.788 0 0 0 7 9.25c0 .3.182.551.33.71a2.8 2.8 0 0 0 .653.505c.52.299 1.23.535 2.017.535c.788 0 1.498-.236 2.017-.535c.26-.15.485-.322.654-.504c.147-.16.329-.41.329-.71a.788.788 0 0 0-.031-.219c-.145.11-.297.21-.453.3A5.108 5.108 0 0 1 10 10a5.108 5.108 0 0 1-2.516-.669a4.273 4.273 0 0 1-.453-.299zM8 7c0-.213.126-.448.483-.655C8.841 6.137 9.374 6 10 6c.626 0 1.159.137 1.517.345c.357.207.483.442.483.655c0 .213-.126.448-.483.655C11.159 7.863 10.626 8 10 8c-.626 0-1.159-.137-1.517-.345C8.126 7.448 8 7.213 8 7zm2-2c-.755 0-1.472.163-2.019.48C7.434 5.798 7 6.313 7 7s.434 1.202.981 1.52C8.528 8.837 9.245 9 10 9c.755 0 1.472-.163 2.019-.48c.547-.318.981-.833.981-1.52s-.434-1.202-.981-1.52C11.472 5.163 10.755 5 10 5z" fill = "currentColor" > < / path > < / g > < / svg >
2023-11-10 13:51:34 +08:00
< div class = "ellipsis" >
< span > Finance< / span >
< / div >
2023-11-10 13:44:10 +08:00
< / a >
< / li > < li class = "active" >
< a href = "/categories/Front-End/" >
2023-12-26 10:56:25 +08:00
2023-11-10 13:51:34 +08:00
< div class = "ellipsis" >
< span > Front-End< / span >
< / div >
2023-11-10 13:44:10 +08:00
< / a >
< / li > < li class = "" >
< a href = "/categories/Hexo/" >
2023-11-10 13:51:34 +08:00
< 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 >
2023-11-10 13:44:10 +08:00
< / a >
2023-11-21 13:49:17 +08:00
< / li > < li class = "" >
< a href = "/categories/%E6%B1%82%E5%AD%A6%E4%B9%8B%E8%B7%AF/" >
2023-12-26 10:56:25 +08:00
2023-11-21 13:49:17 +08:00
< div class = "ellipsis" >
< span > 求学之路< / span >
< / div >
< / a >
2023-11-11 18:48:29 +08:00
< / li > < li class = "" >
< a href = "/categories/%E8%87%AA%E5%AA%92%E4%BD%93/" >
2023-11-11 18:50:08 +08:00
< 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 >
2023-11-11 18:48:29 +08:00
< div class = "ellipsis" >
< span > 自媒体< / span >
< / div >
< / a >
2023-11-10 13:44:10 +08:00
< / li > < / ul >
2023-12-25 16:39:03 +08:00
< / nav >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< script src = "/js/118098c2.js" > < / script >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< / 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 >
2023-11-06 16:05:27 +08:00
< / div >
< / aside >
< main >
2023-12-26 10:56:25 +08:00
< link rel = "stylesheet" href = "/css/9bb9a539.css" >
2023-11-06 16:05:27 +08:00
< div class = "post-container" >
2023-12-25 16:39:03 +08:00
< header >
< div class = "left" >
2023-11-06 16:05:27 +08:00
2023-12-25 16:39:03 +08:00
< link rel = "stylesheet" href = "/css/7d333f9e.css" >
2023-11-06 16:05:27 +08:00
< nav class = "breadcrumb" >
2023-12-25 16:39:03 +08:00
< 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" >
2023-11-06 16:05:27 +08:00
< 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 >
2023-12-25 16:39:03 +08:00
< a class = "ellipsis" href = "/categories/Front-End/" >
Front-End
< / a >
< svg class = "arrow" xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 20 20" >
2023-11-06 16:05:27 +08:00
< 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 >
2023-12-25 16:39:03 +08:00
< span class = "ellipsis" >
Git
< / span >
< / section >
2023-11-06 16:05:27 +08:00
< / nav >
< script src = "/js/31d6cfe0.js" > < / script >
2023-12-25 16:39:03 +08:00
< / 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" >
2023-11-06 16:05:27 +08:00
< div class = "article-container" >
<!-- 渲染文章内容 -->
2023-11-08 13:45:34 +08:00
< article >
2023-12-25 16:39:03 +08:00
<!-- 文章标题 -->
< h1 class = "post-title" > Git< / h1 >
< div class = "last-updated" >
上次更新: 2023-11-06 16:02:34
< / div >
<!-- 文章 -->
2023-11-08 13:45:34 +08:00
< h1 id = "GIT-最佳实践" > < a href = "#GIT-最佳实践" class = "headerlink" title = "GIT 最佳实践" > < / a > GIT 最佳实践< / h1 > < p > GIT 本质是一个数据库,用来存代码的< / p >
2023-11-06 16:05:27 +08:00
< 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 -> 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 ./ 先把工作区生成 git 对象,放到版本库,然后再放到暂存区< / p >
< / blockquote >
< h3 id = "暂存区提交到版本库" > < a href = "#暂存区提交到版本库" class = "headerlink" title = "暂存区提交到版本库" > < / a > 暂存区提交到版本库< / h3 > < p > < code > git commit -m ' comment' < / 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" > { < / span > < span class = "token punctuation" > } < / 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" > ${ < / span > startTime< span class = "token interpolation-punctuation punctuation" > } < / span > < / span > < span class = "token string" > " --until="< / span > < span class = "token interpolation" > < span class = "token interpolation-punctuation punctuation" > ${ < / span > endTime< span class = "token interpolation-punctuation punctuation" > } < / 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" > ${ < / span > startTime< span class = "token interpolation-punctuation punctuation" > } < / span > < / span > < span class = "token string" > " --until="< / span > < span class = "token interpolation" > < span class = "token interpolation-punctuation punctuation" > ${ < / span > endTime< span class = "token interpolation-punctuation punctuation" > } < / 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" > { < / 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{ 4} .\d{ 2} .\d{ 2} < / 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" > } < / span > < span class = "token punctuation" > ,< / span >
< span class = "token punctuation" > { < / 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{ 4} .\d{ 2} .\d{ 2} < / 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" > } < / span > < span class = "token punctuation" > ,< / span >
< span class = "token punctuation" > { < / 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" > } < / 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" > { < / span >
< span class = "token keyword" > const< / span > < span class = "token punctuation" > { < / span > startDate< span class = "token punctuation" > ,< / span > endDate< span class = "token punctuation" > ,< / span > notifyWxrobot < span class = "token punctuation" > } < / 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" > { < / span > < span class = "token punctuation" > } < / 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" > { < / 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" > { < / 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" > { < / span >
< span class = "token literal-property property" > content< / span > < span class = "token operator" > :< / span > fmt< span class = "token punctuation" > ,< / span >
< span class = "token punctuation" > } < / span > < span class = "token punctuation" > ,< / span >
< span class = "token punctuation" > } < / span > < span class = "token punctuation" > )< / span > < span class = "token punctuation" > ;< / 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" > 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" > { < / 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" > { < / span >
< span class = "token comment" > // Prompt couldn't be rendered in the current environment< / span >
< span class = "token punctuation" > } < / span > < span class = "token keyword" > else< / span > < span class = "token punctuation" > { < / span >
< span class = "token comment" > // Something else went wrong< / span >
< span class = "token punctuation" > } < / span >
< span class = "token punctuation" > } < / 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" > { < / span >
< span class = "token property" > "husky"< / span > < span class = "token operator" > :< / span > < span class = "token punctuation" > { < / span >
< span class = "token property" > "hooks"< / span > < span class = "token operator" > :< / span > < span class = "token punctuation" > { < / 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" > } < / 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 > < / 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/ 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/ 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" > & & < / 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" > '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc } '< / 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" > '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc } '< / 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 > ,仓库设置= > 管理 GIT 钩子= > 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" > ${ GIT_WORK_TREE} < / span > /.git
< span class = "token builtin class-name" > cd< / span > < span class = "token variable" > ${ GIT_WORK_TREE} < / 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 >
2023-11-08 13:45:34 +08:00
2023-12-25 16:39:03 +08:00
< div class = "post-tags" >
<!-- 文章tags -->
< / div >
< p class = "motto" > 重拾纯粹的写作< / p >
2023-11-08 13:45:34 +08:00
< / article >
2023-11-06 16:05:27 +08:00
<!-- 评论 -->
< div id = "vcomments" > < / div >
< / div >
< / main >
2023-12-25 16:39:03 +08:00
<!-- 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" >
2023-12-26 10:56:25 +08:00
< 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 >
2023-12-25 16:39:03 +08:00
<!-- 文章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%E
< / div >
< / div >
< / cosy-drag-box >
2023-11-06 16:05:27 +08:00
< / div >
2023-12-25 16:39:03 +08:00
2023-11-06 16:05:27 +08:00
< / div >
< script >
2023-11-08 10:11:56 +08:00
window.page = {
use: ''
}
2023-11-06 16:05:27 +08:00
window.katex = {
2023-11-08 10:11:56 +08:00
enable: "",
2023-11-06 16:05:27 +08:00
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 = {
2023-11-08 10:11:56 +08:00
enable: "",
2023-11-15 10:21:41 +08:00
theme: "",
2023-11-06 16:05:27 +08:00
cdn: "//cdn.jsdelivr.net/npm/mermaid@10.4.0/dist/mermaid.min.js",
}
window.valine = {
2023-11-08 10:11:56 +08:00
enable: "",
2023-11-06 16:05:27 +08:00
appId: 'TisMit6uhflounFqAN3ZGjgq-MdYXbMMI',
appKey: 'CdjirjYdz07U5i62ElsJvXUh',
avatar: 'monsterid',
cdn: '//unpkg.com/valine@latest/dist/Valine.min.js',
serverURLs: '//tismit6u.api.lncldglobal.com'
};
< / script >
2023-12-25 16:39:03 +08:00
< script src = "/js/0af3d6bb.js" > < / script >
2023-11-06 16:05:27 +08:00
< / main >
< / body >
2023-12-25 16:39:03 +08:00
2023-11-06 16:05:27 +08:00
< script >
2023-12-25 16:39:03 +08:00
window.theme = {
color: 'hsl(238,50%,56%)'
2023-11-06 16:05:27 +08:00
}
< / script >
2023-12-25 16:39:03 +08:00
< script src = "/js/9c8197f9.js" > < / script >
2023-11-06 16:05:27 +08:00
< / html >