[{"data":1,"prerenderedAt":1080},["Reactive",2],{"article-20230903":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":7,"published":9,"categories":10,"tags":12,"slug":8,"body":16,"_type":1075,"_id":1076,"_source":1077,"_file":1078,"_extension":1079},"/articles/20230903","articles",false,"","使用这个git工具，让你的工作效率大幅上升","2023/9/3 21:46:00",[11],"前端开发",[13,14,15],"git","node.js","shell",{"type":17,"children":18,"toc":1068},"root",[19,30,37,42,47,96,101,106,115,120,125,130,135,148,215,228,233,254,273,278,327,332,338,343,348,639,644,659,668,681,689,694,714,719,958,963,971,998,1021,1026,1031,1036,1041,1062],{"type":20,"tag":21,"props":22,"children":23},"element","p",{},[24],{"type":20,"tag":25,"props":26,"children":29},"img",{"alt":27,"src":28},"Sep-03-2023 18-40-17","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Sep-03-2023%2018-40-17.gif",[],{"type":20,"tag":31,"props":32,"children":34},"h2",{"id":33},"背景",[35],{"type":36,"value":33},"text",{"type":20,"tag":21,"props":38,"children":39},{},[40],{"type":36,"value":41},"在公司项目使用git管理代码记录的背景下，每当我的需求进入了提测阶段，测试总能从我的代码中找出一堆bug（什么，你写的代码从来没有bug？那我先叫你声大佬）。一般我们要做的就是在需求分支中修复bug，然后切到测试分支，合并我们的功能分支，最后推送测试分支到远程触发自动构建和部署。如果过一会测试又发现了新的bug，那么就得继续重复上述的步骤。",{"type":20,"tag":21,"props":43,"children":44},{},[45],{"type":36,"value":46},"你发现了没有，每当我们修复了bug，合并到测试分支时，存在着极其重复而又繁琐的分支操作环节：",{"type":20,"tag":48,"props":49,"children":50},"ol",{},[51,64,75,86],{"type":20,"tag":52,"props":53,"children":54},"li",{},[55,62],{"type":20,"tag":56,"props":57,"children":59},"code",{"className":58},[],[60],{"type":36,"value":61},"git checkout",{"type":36,"value":63}," 切到测试分支。",{"type":20,"tag":52,"props":65,"children":66},{},[67,73],{"type":20,"tag":56,"props":68,"children":70},{"className":69},[],[71],{"type":36,"value":72},"git merge",{"type":36,"value":74}," 合并我们刚刚修复的功能分支。",{"type":20,"tag":52,"props":76,"children":77},{},[78,84],{"type":20,"tag":56,"props":79,"children":81},{"className":80},[],[82],{"type":36,"value":83},"git push",{"type":36,"value":85}," 推送到远程。",{"type":20,"tag":52,"props":87,"children":88},{},[89,94],{"type":20,"tag":56,"props":90,"children":92},{"className":91},[],[93],{"type":36,"value":61},{"type":36,"value":95}," 切回功能分支。",{"type":20,"tag":21,"props":97,"children":98},{},[99],{"type":36,"value":100},"这4个步骤贯穿着我们修复bug生涯的最后一环。而且当功能分支很长又难记时，你是不是得偷偷看看分支名，或者复制粘贴一下到命令行，简直是令人抓狂。",{"type":20,"tag":21,"props":102,"children":103},{},[104],{"type":36,"value":105},"不习惯敲命令的一些同学，会使用图形界面对分支进行操作，不过这样的话手就不得不离开键盘，用鼠标去点点点。",{"type":20,"tag":107,"props":108,"children":109},"blockquote",{},[110],{"type":20,"tag":21,"props":111,"children":112},{},[113],{"type":36,"value":114},"俗话说得好：浪费时间，就是浪费生命。",{"type":20,"tag":21,"props":116,"children":117},{},[118],{"type":36,"value":119},"有一天我突发奇想，如果能有一个CLI工具，帮我自动操作分支的合并，让我从这个重复又繁琐的操作中解放出来，那我岂不是能做很多其他的事情了（摸鱼）。虽然一次的自动操作可以节省几秒钟，但是千万不要小看了这几秒钟，日积月累之下难以想象它能给你带来多少收益，正所谓水滴能把石穿透。",{"type":20,"tag":21,"props":121,"children":122},{},[123],{"type":36,"value":124},"想到这里我就马不停蹄地投入到这个CLI工具的研发之中。。。",{"type":20,"tag":21,"props":126,"children":127},{},[128],{"type":36,"value":129},"下面我们介绍一下这个工具的使用，看他是如何解放你的双手的。",{"type":20,"tag":31,"props":131,"children":133},{"id":132},"工具使用介绍",[134],{"type":36,"value":132},{"type":20,"tag":21,"props":136,"children":137},{},[138,140,146],{"type":36,"value":139},"全局安装",{"type":20,"tag":56,"props":141,"children":143},{"className":142},[],[144],{"type":36,"value":145},"@johnhom/mg-cli",{"type":36,"value":147},"：",{"type":20,"tag":149,"props":150,"children":153},"pre",{"className":151,"code":152,"language":15,"meta":7,"style":7},"language-shell shiki shiki-themes github-dark","npm install -g @johnhom/mg-cli\n\n# 或者\n# yarn global add @johnhom/mg-cli\n",[154],{"type":20,"tag":56,"props":155,"children":156},{"__ignoreMap":7},[157,186,196,206],{"type":20,"tag":158,"props":159,"children":162},"span",{"class":160,"line":161},"line",1,[163,169,175,181],{"type":20,"tag":158,"props":164,"children":166},{"style":165},"--shiki-default:#B392F0",[167],{"type":36,"value":168},"npm",{"type":20,"tag":158,"props":170,"children":172},{"style":171},"--shiki-default:#9ECBFF",[173],{"type":36,"value":174}," install",{"type":20,"tag":158,"props":176,"children":178},{"style":177},"--shiki-default:#79B8FF",[179],{"type":36,"value":180}," -g",{"type":20,"tag":158,"props":182,"children":183},{"style":171},[184],{"type":36,"value":185}," @johnhom/mg-cli\n",{"type":20,"tag":158,"props":187,"children":189},{"class":160,"line":188},2,[190],{"type":20,"tag":158,"props":191,"children":193},{"emptyLinePlaceholder":192},true,[194],{"type":36,"value":195},"\n",{"type":20,"tag":158,"props":197,"children":199},{"class":160,"line":198},3,[200],{"type":20,"tag":158,"props":201,"children":203},{"style":202},"--shiki-default:#6A737D",[204],{"type":36,"value":205},"# 或者\n",{"type":20,"tag":158,"props":207,"children":209},{"class":160,"line":208},4,[210],{"type":20,"tag":158,"props":211,"children":212},{"style":202},[213],{"type":36,"value":214},"# yarn global add @johnhom/mg-cli\n",{"type":20,"tag":21,"props":216,"children":217},{},[218,220,226],{"type":36,"value":219},"全局安装完成之后，我们就可以在终端命令行里运行",{"type":20,"tag":56,"props":221,"children":223},{"className":222},[],[224],{"type":36,"value":225},"amg",{"type":36,"value":227},"这个命令。",{"type":20,"tag":21,"props":229,"children":230},{},[231],{"type":36,"value":232},"使用方法：",{"type":20,"tag":21,"props":234,"children":235},{},[236,238,244,246,252],{"type":36,"value":237},"假设你当前项目所在的分支为：",{"type":20,"tag":56,"props":239,"children":241},{"className":240},[],[242],{"type":36,"value":243},"feature/a",{"type":36,"value":245},"，你想要把这个分支合并到",{"type":20,"tag":56,"props":247,"children":249},{"className":248},[],[250],{"type":36,"value":251},"dev",{"type":36,"value":253},"，你只需要执行以下命令：",{"type":20,"tag":149,"props":255,"children":257},{"className":151,"code":256,"language":15,"meta":7,"style":7},"amg dev\n",[258],{"type":20,"tag":56,"props":259,"children":260},{"__ignoreMap":7},[261],{"type":20,"tag":158,"props":262,"children":263},{"class":160,"line":161},[264,268],{"type":20,"tag":158,"props":265,"children":266},{"style":165},[267],{"type":36,"value":225},{"type":20,"tag":158,"props":269,"children":270},{"style":171},[271],{"type":36,"value":272}," dev\n",{"type":20,"tag":21,"props":274,"children":275},{},[276],{"type":36,"value":277},"上述命令执行后，终端会自动按进行如下操作：",{"type":20,"tag":48,"props":279,"children":280},{},[281,292,297,302,312,317,322],{"type":20,"tag":52,"props":282,"children":283},{},[284,286],{"type":36,"value":285},"在当前分支执行",{"type":20,"tag":56,"props":287,"children":289},{"className":288},[],[290],{"type":36,"value":291},"git pull",{"type":20,"tag":52,"props":293,"children":294},{},[295],{"type":36,"value":296},"获取当前分支的名称",{"type":20,"tag":52,"props":298,"children":299},{},[300],{"type":36,"value":301},"切换到目标分支dev",{"type":20,"tag":52,"props":303,"children":304},{},[305,307],{"type":36,"value":306},"执行",{"type":20,"tag":56,"props":308,"children":310},{"className":309},[],[311],{"type":36,"value":291},{"type":20,"tag":52,"props":313,"children":314},{},[315],{"type":36,"value":316},"合并分支",{"type":20,"tag":52,"props":318,"children":319},{},[320],{"type":36,"value":321},"询问是否要推到远程",{"type":20,"tag":52,"props":323,"children":324},{},[325],{"type":36,"value":326},"询问是否要切回源分支",{"type":20,"tag":21,"props":328,"children":329},{},[330],{"type":36,"value":331},"我们来看看运行的gif图：",{"type":20,"tag":21,"props":333,"children":334},{},[335],{"type":20,"tag":25,"props":336,"children":337},{"alt":27,"src":28},[],{"type":20,"tag":21,"props":339,"children":340},{},[341],{"type":36,"value":342},"nice！",{"type":20,"tag":21,"props":344,"children":345},{},[346],{"type":36,"value":347},"下面展示具体的用法：",{"type":20,"tag":149,"props":349,"children":351},{"className":151,"code":350,"language":15,"meta":7,"style":7},"Usage:\n  $ amg [target_branch]\n\nCommands:\n  [target_branch]  merge current branch into target_branch\n\nFor more info, run any command with the `--help` flag:\n  $ amg --help\n\nOptions:\n  -h, --help     Display this message \n  -v, --version  Display version number \n\nExamples:\namg master    把当前分支自动合并到master\n",[352],{"type":20,"tag":56,"props":353,"children":354},{"__ignoreMap":7},[355,363,382,389,397,431,439,503,520,528,537,571,604,612,621],{"type":20,"tag":158,"props":356,"children":357},{"class":160,"line":161},[358],{"type":20,"tag":158,"props":359,"children":360},{"style":165},[361],{"type":36,"value":362},"Usage:\n",{"type":20,"tag":158,"props":364,"children":365},{"class":160,"line":188},[366,371,376],{"type":20,"tag":158,"props":367,"children":368},{"style":165},[369],{"type":36,"value":370},"  $",{"type":20,"tag":158,"props":372,"children":373},{"style":171},[374],{"type":36,"value":375}," amg",{"type":20,"tag":158,"props":377,"children":379},{"style":378},"--shiki-default:#E1E4E8",[380],{"type":36,"value":381}," [target_branch]\n",{"type":20,"tag":158,"props":383,"children":384},{"class":160,"line":198},[385],{"type":20,"tag":158,"props":386,"children":387},{"emptyLinePlaceholder":192},[388],{"type":36,"value":195},{"type":20,"tag":158,"props":390,"children":391},{"class":160,"line":208},[392],{"type":20,"tag":158,"props":393,"children":394},{"style":165},[395],{"type":36,"value":396},"Commands:\n",{"type":20,"tag":158,"props":398,"children":400},{"class":160,"line":399},5,[401,406,411,416,421,426],{"type":20,"tag":158,"props":402,"children":403},{"style":378},[404],{"type":36,"value":405},"  [target_branch]  ",{"type":20,"tag":158,"props":407,"children":408},{"style":165},[409],{"type":36,"value":410},"merge",{"type":20,"tag":158,"props":412,"children":413},{"style":171},[414],{"type":36,"value":415}," current",{"type":20,"tag":158,"props":417,"children":418},{"style":171},[419],{"type":36,"value":420}," branch",{"type":20,"tag":158,"props":422,"children":423},{"style":171},[424],{"type":36,"value":425}," into",{"type":20,"tag":158,"props":427,"children":428},{"style":171},[429],{"type":36,"value":430}," target_branch\n",{"type":20,"tag":158,"props":432,"children":434},{"class":160,"line":433},6,[435],{"type":20,"tag":158,"props":436,"children":437},{"emptyLinePlaceholder":192},[438],{"type":36,"value":195},{"type":20,"tag":158,"props":440,"children":442},{"class":160,"line":441},7,[443,448,453,458,463,468,473,478,483,488,493,498],{"type":20,"tag":158,"props":444,"children":445},{"style":165},[446],{"type":36,"value":447},"For",{"type":20,"tag":158,"props":449,"children":450},{"style":171},[451],{"type":36,"value":452}," more",{"type":20,"tag":158,"props":454,"children":455},{"style":171},[456],{"type":36,"value":457}," info,",{"type":20,"tag":158,"props":459,"children":460},{"style":171},[461],{"type":36,"value":462}," run",{"type":20,"tag":158,"props":464,"children":465},{"style":171},[466],{"type":36,"value":467}," any",{"type":20,"tag":158,"props":469,"children":470},{"style":171},[471],{"type":36,"value":472}," command",{"type":20,"tag":158,"props":474,"children":475},{"style":171},[476],{"type":36,"value":477}," with",{"type":20,"tag":158,"props":479,"children":480},{"style":171},[481],{"type":36,"value":482}," the",{"type":20,"tag":158,"props":484,"children":485},{"style":171},[486],{"type":36,"value":487}," `",{"type":20,"tag":158,"props":489,"children":490},{"style":165},[491],{"type":36,"value":492},"--help",{"type":20,"tag":158,"props":494,"children":495},{"style":171},[496],{"type":36,"value":497},"`",{"type":20,"tag":158,"props":499,"children":500},{"style":165},[501],{"type":36,"value":502}," flag:\n",{"type":20,"tag":158,"props":504,"children":506},{"class":160,"line":505},8,[507,511,515],{"type":20,"tag":158,"props":508,"children":509},{"style":165},[510],{"type":36,"value":370},{"type":20,"tag":158,"props":512,"children":513},{"style":171},[514],{"type":36,"value":375},{"type":20,"tag":158,"props":516,"children":517},{"style":177},[518],{"type":36,"value":519}," --help\n",{"type":20,"tag":158,"props":521,"children":523},{"class":160,"line":522},9,[524],{"type":20,"tag":158,"props":525,"children":526},{"emptyLinePlaceholder":192},[527],{"type":36,"value":195},{"type":20,"tag":158,"props":529,"children":531},{"class":160,"line":530},10,[532],{"type":20,"tag":158,"props":533,"children":534},{"style":165},[535],{"type":36,"value":536},"Options:\n",{"type":20,"tag":158,"props":538,"children":540},{"class":160,"line":539},11,[541,546,551,556,561,566],{"type":20,"tag":158,"props":542,"children":543},{"style":165},[544],{"type":36,"value":545},"  -h,",{"type":20,"tag":158,"props":547,"children":548},{"style":177},[549],{"type":36,"value":550}," --help",{"type":20,"tag":158,"props":552,"children":553},{"style":171},[554],{"type":36,"value":555},"     Display",{"type":20,"tag":158,"props":557,"children":558},{"style":171},[559],{"type":36,"value":560}," this",{"type":20,"tag":158,"props":562,"children":563},{"style":171},[564],{"type":36,"value":565}," message",{"type":20,"tag":158,"props":567,"children":568},{"style":378},[569],{"type":36,"value":570}," \n",{"type":20,"tag":158,"props":572,"children":574},{"class":160,"line":573},12,[575,580,585,590,595,600],{"type":20,"tag":158,"props":576,"children":577},{"style":165},[578],{"type":36,"value":579},"  -v,",{"type":20,"tag":158,"props":581,"children":582},{"style":177},[583],{"type":36,"value":584}," --version",{"type":20,"tag":158,"props":586,"children":587},{"style":171},[588],{"type":36,"value":589},"  Display",{"type":20,"tag":158,"props":591,"children":592},{"style":171},[593],{"type":36,"value":594}," version",{"type":20,"tag":158,"props":596,"children":597},{"style":171},[598],{"type":36,"value":599}," number",{"type":20,"tag":158,"props":601,"children":602},{"style":378},[603],{"type":36,"value":570},{"type":20,"tag":158,"props":605,"children":607},{"class":160,"line":606},13,[608],{"type":20,"tag":158,"props":609,"children":610},{"emptyLinePlaceholder":192},[611],{"type":36,"value":195},{"type":20,"tag":158,"props":613,"children":615},{"class":160,"line":614},14,[616],{"type":20,"tag":158,"props":617,"children":618},{"style":165},[619],{"type":36,"value":620},"Examples:\n",{"type":20,"tag":158,"props":622,"children":624},{"class":160,"line":623},15,[625,629,634],{"type":20,"tag":158,"props":626,"children":627},{"style":165},[628],{"type":36,"value":225},{"type":20,"tag":158,"props":630,"children":631},{"style":171},[632],{"type":36,"value":633}," master",{"type":20,"tag":158,"props":635,"children":636},{"style":171},[637],{"type":36,"value":638},"    把当前分支自动合并到master\n",{"type":20,"tag":21,"props":640,"children":641},{},[642],{"type":36,"value":643},"假设你当前项目所在的分支为：feature/a，你想要把这个分支合并到dev，并自动上传到远程仓库，你只需要执行以下命令：",{"type":20,"tag":149,"props":645,"children":648},{"className":646,"code":256,"language":647,"meta":7,"style":7},"language-js shiki shiki-themes github-dark","js",[649],{"type":20,"tag":56,"props":650,"children":651},{"__ignoreMap":7},[652],{"type":20,"tag":158,"props":653,"children":654},{"class":160,"line":161},[655],{"type":20,"tag":158,"props":656,"children":657},{"style":378},[658],{"type":36,"value":256},{"type":20,"tag":21,"props":660,"children":661},{},[662],{"type":20,"tag":663,"props":664,"children":665},"strong",{},[666],{"type":36,"value":667},"自动合并过程中如果遇到了冲突",{"type":20,"tag":21,"props":669,"children":670},{},[671,673,679],{"type":36,"value":672},"假设在合并分支的过程中遇到了冲突，",{"type":20,"tag":56,"props":674,"children":676},{"className":675},[],[677],{"type":36,"value":678},"mg-cli",{"type":36,"value":680},"会识别到冲突，并且中断后续的操作，最后提示你需要处理，如下图所示：",{"type":20,"tag":21,"props":682,"children":683},{},[684],{"type":20,"tag":25,"props":685,"children":688},{"alt":686,"src":687},"Pasted image 20230903213552","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Pasted%20image%2020230903213552.png",[],{"type":20,"tag":31,"props":690,"children":692},{"id":691},"实现原理",[693],{"type":36,"value":691},{"type":20,"tag":21,"props":695,"children":696},{},[697,699,705,707,712],{"type":36,"value":698},"原理其实也特别的简单，其实就是使用Node.js自带的",{"type":20,"tag":56,"props":700,"children":702},{"className":701},[],[703],{"type":36,"value":704},"child_process",{"type":36,"value":706},"模块创建子进程来执行一些",{"type":20,"tag":56,"props":708,"children":710},{"className":709},[],[711],{"type":36,"value":15},{"type":36,"value":713},"的命令。",{"type":20,"tag":21,"props":715,"children":716},{},[717],{"type":36,"value":718},"下面我们看一个简单的使用例子：",{"type":20,"tag":149,"props":720,"children":722},{"className":646,"code":721,"language":647,"meta":7,"style":7},"const childProcess = require('child_process');\n\n// 在子进程中执行git branch\nchildProcess.exec('git branch', (error, stdout, stderr) => {\n  if (error) {\n    console.error(error);\n    return;\n  }\n\n  // 输出子进程运行之后的输出内容\n  console.log('----------johnhomLogDebug stdout\\n', stdout);\n});\n",[723],{"type":20,"tag":56,"props":724,"children":725},{"__ignoreMap":7},[726,765,772,780,847,860,877,890,898,905,913,950],{"type":20,"tag":158,"props":727,"children":728},{"class":160,"line":161},[729,735,740,745,750,755,760],{"type":20,"tag":158,"props":730,"children":732},{"style":731},"--shiki-default:#F97583",[733],{"type":36,"value":734},"const",{"type":20,"tag":158,"props":736,"children":737},{"style":177},[738],{"type":36,"value":739}," childProcess",{"type":20,"tag":158,"props":741,"children":742},{"style":731},[743],{"type":36,"value":744}," =",{"type":20,"tag":158,"props":746,"children":747},{"style":165},[748],{"type":36,"value":749}," require",{"type":20,"tag":158,"props":751,"children":752},{"style":378},[753],{"type":36,"value":754},"(",{"type":20,"tag":158,"props":756,"children":757},{"style":171},[758],{"type":36,"value":759},"'child_process'",{"type":20,"tag":158,"props":761,"children":762},{"style":378},[763],{"type":36,"value":764},");\n",{"type":20,"tag":158,"props":766,"children":767},{"class":160,"line":188},[768],{"type":20,"tag":158,"props":769,"children":770},{"emptyLinePlaceholder":192},[771],{"type":36,"value":195},{"type":20,"tag":158,"props":773,"children":774},{"class":160,"line":198},[775],{"type":20,"tag":158,"props":776,"children":777},{"style":202},[778],{"type":36,"value":779},"// 在子进程中执行git branch\n",{"type":20,"tag":158,"props":781,"children":782},{"class":160,"line":208},[783,788,793,797,802,807,813,818,823,827,832,837,842],{"type":20,"tag":158,"props":784,"children":785},{"style":378},[786],{"type":36,"value":787},"childProcess.",{"type":20,"tag":158,"props":789,"children":790},{"style":165},[791],{"type":36,"value":792},"exec",{"type":20,"tag":158,"props":794,"children":795},{"style":378},[796],{"type":36,"value":754},{"type":20,"tag":158,"props":798,"children":799},{"style":171},[800],{"type":36,"value":801},"'git branch'",{"type":20,"tag":158,"props":803,"children":804},{"style":378},[805],{"type":36,"value":806},", (",{"type":20,"tag":158,"props":808,"children":810},{"style":809},"--shiki-default:#FFAB70",[811],{"type":36,"value":812},"error",{"type":20,"tag":158,"props":814,"children":815},{"style":378},[816],{"type":36,"value":817},", ",{"type":20,"tag":158,"props":819,"children":820},{"style":809},[821],{"type":36,"value":822},"stdout",{"type":20,"tag":158,"props":824,"children":825},{"style":378},[826],{"type":36,"value":817},{"type":20,"tag":158,"props":828,"children":829},{"style":809},[830],{"type":36,"value":831},"stderr",{"type":20,"tag":158,"props":833,"children":834},{"style":378},[835],{"type":36,"value":836},") ",{"type":20,"tag":158,"props":838,"children":839},{"style":731},[840],{"type":36,"value":841},"=>",{"type":20,"tag":158,"props":843,"children":844},{"style":378},[845],{"type":36,"value":846}," {\n",{"type":20,"tag":158,"props":848,"children":849},{"class":160,"line":399},[850,855],{"type":20,"tag":158,"props":851,"children":852},{"style":731},[853],{"type":36,"value":854},"  if",{"type":20,"tag":158,"props":856,"children":857},{"style":378},[858],{"type":36,"value":859}," (error) {\n",{"type":20,"tag":158,"props":861,"children":862},{"class":160,"line":433},[863,868,872],{"type":20,"tag":158,"props":864,"children":865},{"style":378},[866],{"type":36,"value":867},"    console.",{"type":20,"tag":158,"props":869,"children":870},{"style":165},[871],{"type":36,"value":812},{"type":20,"tag":158,"props":873,"children":874},{"style":378},[875],{"type":36,"value":876},"(error);\n",{"type":20,"tag":158,"props":878,"children":879},{"class":160,"line":441},[880,885],{"type":20,"tag":158,"props":881,"children":882},{"style":731},[883],{"type":36,"value":884},"    return",{"type":20,"tag":158,"props":886,"children":887},{"style":378},[888],{"type":36,"value":889},";\n",{"type":20,"tag":158,"props":891,"children":892},{"class":160,"line":505},[893],{"type":20,"tag":158,"props":894,"children":895},{"style":378},[896],{"type":36,"value":897},"  }\n",{"type":20,"tag":158,"props":899,"children":900},{"class":160,"line":522},[901],{"type":20,"tag":158,"props":902,"children":903},{"emptyLinePlaceholder":192},[904],{"type":36,"value":195},{"type":20,"tag":158,"props":906,"children":907},{"class":160,"line":530},[908],{"type":20,"tag":158,"props":909,"children":910},{"style":202},[911],{"type":36,"value":912},"  // 输出子进程运行之后的输出内容\n",{"type":20,"tag":158,"props":914,"children":915},{"class":160,"line":539},[916,921,926,930,935,940,945],{"type":20,"tag":158,"props":917,"children":918},{"style":378},[919],{"type":36,"value":920},"  console.",{"type":20,"tag":158,"props":922,"children":923},{"style":165},[924],{"type":36,"value":925},"log",{"type":20,"tag":158,"props":927,"children":928},{"style":378},[929],{"type":36,"value":754},{"type":20,"tag":158,"props":931,"children":932},{"style":171},[933],{"type":36,"value":934},"'----------johnhomLogDebug stdout",{"type":20,"tag":158,"props":936,"children":937},{"style":177},[938],{"type":36,"value":939},"\\n",{"type":20,"tag":158,"props":941,"children":942},{"style":171},[943],{"type":36,"value":944},"'",{"type":20,"tag":158,"props":946,"children":947},{"style":378},[948],{"type":36,"value":949},", stdout);\n",{"type":20,"tag":158,"props":951,"children":952},{"class":160,"line":573},[953],{"type":20,"tag":158,"props":954,"children":955},{"style":378},[956],{"type":36,"value":957},"});\n",{"type":20,"tag":21,"props":959,"children":960},{},[961],{"type":36,"value":962},"运行以上代码之后：",{"type":20,"tag":21,"props":964,"children":965},{},[966],{"type":20,"tag":25,"props":967,"children":970},{"alt":968,"src":969},"Pasted image 20230903190856","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Pasted%20image%2020230903190856.png",[],{"type":20,"tag":21,"props":972,"children":973},{},[974,976,981,983,989,991,996],{"type":36,"value":975},"以上就是一个简单的例子，通过",{"type":20,"tag":56,"props":977,"children":979},{"className":978},[],[980],{"type":36,"value":704},{"type":36,"value":982},"模块衍生一个shell进程，然后在该进程中执行了",{"type":20,"tag":56,"props":984,"children":986},{"className":985},[],[987],{"type":36,"value":988},"git branch",{"type":36,"value":990},"命令，完成之后把命令输出的内容作为",{"type":20,"tag":56,"props":992,"children":994},{"className":993},[],[995],{"type":36,"value":822},{"type":36,"value":997},"放入回调函数中。",{"type":20,"tag":21,"props":999,"children":1000},{},[1001,1003,1012,1014,1019],{"type":36,"value":1002},"一般我们都会使用第三方库",{"type":20,"tag":1004,"props":1005,"children":1009},"a",{"href":1006,"rel":1007},"https://github.com/shelljs/shelljs",[1008],"nofollow",[1010],{"type":36,"value":1011},"shelljs",{"type":36,"value":1013},"来代替",{"type":20,"tag":56,"props":1015,"children":1017},{"className":1016},[],[1018],{"type":36,"value":704},{"type":36,"value":1020},"，它提供了更高级的API和更简洁的语法，适用于执行简单的Shell命令和一些常见的文件和目录操作。",{"type":20,"tag":31,"props":1022,"children":1024},{"id":1023},"总结",[1025],{"type":36,"value":1023},{"type":20,"tag":21,"props":1027,"children":1028},{},[1029],{"type":36,"value":1030},"通过这次git工具的开发呢，让我发现在编程生涯中，其实很多重复的事情，其实都可以通过写一个Node.js的程序去处理和解决，以此解放我们的双手，极大地提升工作的效率。只要你敢想，然后动手造出来。",{"type":20,"tag":21,"props":1032,"children":1033},{},[1034],{"type":36,"value":1035},"其实工具并不缺乏，缺乏的只是你的想象力还有珍贵的行动力。",{"type":20,"tag":31,"props":1037,"children":1039},{"id":1038},"相关的工具链接",[1040],{"type":36,"value":1038},{"type":20,"tag":1042,"props":1043,"children":1044},"ul",{},[1045,1054],{"type":20,"tag":52,"props":1046,"children":1047},{},[1048],{"type":20,"tag":1004,"props":1049,"children":1052},{"href":1050,"rel":1051},"https://github.com/johnhom1024/tool-cli/tree/main/packages/mg-cli",[1008],[1053],{"type":36,"value":145},{"type":20,"tag":52,"props":1055,"children":1056},{},[1057],{"type":20,"tag":1004,"props":1058,"children":1060},{"href":1006,"rel":1059},[1008],[1061],{"type":36,"value":1011},{"type":20,"tag":1063,"props":1064,"children":1065},"style",{},[1066],{"type":36,"value":1067},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":188,"depth":188,"links":1069},[1070,1071,1072,1073,1074],{"id":33,"depth":188,"text":33},{"id":132,"depth":188,"text":132},{"id":691,"depth":188,"text":691},{"id":1023,"depth":188,"text":1023},{"id":1038,"depth":188,"text":1038},"markdown","content:articles:20230903.md","content","articles/20230903.md","md",1772793492645]