123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <title>Git基础与命令 | 彪哥博客</title>
- <meta name="generator" content="VuePress 1.9.5">
- <link rel="icon" href="/blog/img/favicon.ico">
- <meta name="description" content="web前端技术博客,专注web前端学习与总结。JavaScript,js,ES6,TypeScript,vue,React,python,css3,html5,Node,git,github等技术文章。">
- <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown">
- <meta name="theme-color" content="#11a8cd">
-
- <link rel="preload" href="/blog/assets/css/0.styles.cf8cd190.css" as="style"><link rel="preload" href="/blog/assets/js/app.68c9df80.js" as="script"><link rel="preload" href="/blog/assets/js/2.395c0d18.js" as="script"><link rel="preload" href="/blog/assets/js/3.6748bd5c.js" as="script"><link rel="preload" href="/blog/assets/js/125.f09bc798.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.cad3aa70.js"><link rel="prefetch" href="/blog/assets/js/100.08a8b2d8.js"><link rel="prefetch" href="/blog/assets/js/101.2aabb12c.js"><link rel="prefetch" href="/blog/assets/js/102.13f3cc4d.js"><link rel="prefetch" href="/blog/assets/js/103.c19aee03.js"><link rel="prefetch" href="/blog/assets/js/104.91a6aec1.js"><link rel="prefetch" href="/blog/assets/js/105.c39c4cd9.js"><link rel="prefetch" href="/blog/assets/js/106.c34bb1d8.js"><link rel="prefetch" href="/blog/assets/js/107.4a53669b.js"><link rel="prefetch" href="/blog/assets/js/108.a43622c2.js"><link rel="prefetch" href="/blog/assets/js/109.3219d87b.js"><link rel="prefetch" href="/blog/assets/js/11.f2e9eca8.js"><link rel="prefetch" href="/blog/assets/js/110.f41596b0.js"><link rel="prefetch" href="/blog/assets/js/111.da99a105.js"><link rel="prefetch" href="/blog/assets/js/112.9dd75c6f.js"><link rel="prefetch" href="/blog/assets/js/113.9322f157.js"><link rel="prefetch" href="/blog/assets/js/114.c5150cc6.js"><link rel="prefetch" href="/blog/assets/js/115.f58b49f8.js"><link rel="prefetch" href="/blog/assets/js/116.8f7d9c6f.js"><link rel="prefetch" href="/blog/assets/js/117.3c970f48.js"><link rel="prefetch" href="/blog/assets/js/118.921e1d54.js"><link rel="prefetch" href="/blog/assets/js/119.0141defb.js"><link rel="prefetch" href="/blog/assets/js/12.98512c60.js"><link rel="prefetch" href="/blog/assets/js/120.de47a761.js"><link rel="prefetch" href="/blog/assets/js/121.a0b3693a.js"><link rel="prefetch" href="/blog/assets/js/122.6c7dd225.js"><link rel="prefetch" href="/blog/assets/js/123.dbff103c.js"><link rel="prefetch" href="/blog/assets/js/124.493776ef.js"><link rel="prefetch" href="/blog/assets/js/126.3e28e8a2.js"><link rel="prefetch" href="/blog/assets/js/127.aad20a7e.js"><link rel="prefetch" href="/blog/assets/js/128.6543adba.js"><link rel="prefetch" href="/blog/assets/js/129.d7c56b92.js"><link rel="prefetch" href="/blog/assets/js/13.a79fa0c7.js"><link rel="prefetch" href="/blog/assets/js/130.593d21f0.js"><link rel="prefetch" href="/blog/assets/js/131.4c90d8b8.js"><link rel="prefetch" href="/blog/assets/js/132.4ad12bdc.js"><link rel="prefetch" href="/blog/assets/js/133.485de1b9.js"><link rel="prefetch" href="/blog/assets/js/134.78bc8f57.js"><link rel="prefetch" href="/blog/assets/js/135.47498729.js"><link rel="prefetch" href="/blog/assets/js/136.d99350df.js"><link rel="prefetch" href="/blog/assets/js/137.35d58a22.js"><link rel="prefetch" href="/blog/assets/js/138.75e29c6f.js"><link rel="prefetch" href="/blog/assets/js/139.5af059c1.js"><link rel="prefetch" href="/blog/assets/js/14.0fdf0c78.js"><link rel="prefetch" href="/blog/assets/js/140.0d9b8fbc.js"><link rel="prefetch" href="/blog/assets/js/141.128b6e26.js"><link rel="prefetch" href="/blog/assets/js/142.d7c4dea7.js"><link rel="prefetch" href="/blog/assets/js/143.9aa933f3.js"><link rel="prefetch" href="/blog/assets/js/144.277e558e.js"><link rel="prefetch" href="/blog/assets/js/145.3b994de3.js"><link rel="prefetch" href="/blog/assets/js/146.24441c89.js"><link rel="prefetch" href="/blog/assets/js/147.f7f1952e.js"><link rel="prefetch" href="/blog/assets/js/148.25581f95.js"><link rel="prefetch" href="/blog/assets/js/149.882bdb5a.js"><link rel="prefetch" href="/blog/assets/js/15.fce722b2.js"><link rel="prefetch" href="/blog/assets/js/150.dc1a32f0.js"><link rel="prefetch" href="/blog/assets/js/151.250a4894.js"><link rel="prefetch" href="/blog/assets/js/152.fa700729.js"><link rel="prefetch" href="/blog/assets/js/153.b007c8a2.js"><link rel="prefetch" href="/blog/assets/js/154.8ab912b6.js"><link rel="prefetch" href="/blog/assets/js/155.5ee5b308.js"><link rel="prefetch" href="/blog/assets/js/156.906dc55e.js"><link rel="prefetch" href="/blog/assets/js/157.08c6766f.js"><link rel="prefetch" href="/blog/assets/js/158.53ad5a6c.js"><link rel="prefetch" href="/blog/assets/js/159.a83db4c9.js"><link rel="prefetch" href="/blog/assets/js/16.7cf1b239.js"><link rel="prefetch" href="/blog/assets/js/160.4cded216.js"><link rel="prefetch" href="/blog/assets/js/161.9471d56d.js"><link rel="prefetch" href="/blog/assets/js/162.0c32d380.js"><link rel="prefetch" href="/blog/assets/js/163.41d60a5c.js"><link rel="prefetch" href="/blog/assets/js/164.6dbc8ae8.js"><link rel="prefetch" href="/blog/assets/js/165.7e1b67fe.js"><link rel="prefetch" href="/blog/assets/js/166.ca626fb4.js"><link rel="prefetch" href="/blog/assets/js/167.2f20b6fa.js"><link rel="prefetch" href="/blog/assets/js/168.2e605db8.js"><link rel="prefetch" href="/blog/assets/js/169.401b96d4.js"><link rel="prefetch" href="/blog/assets/js/17.cea117e8.js"><link rel="prefetch" href="/blog/assets/js/170.7c8b0366.js"><link rel="prefetch" href="/blog/assets/js/171.c3155533.js"><link rel="prefetch" href="/blog/assets/js/172.b659d767.js"><link rel="prefetch" href="/blog/assets/js/173.62c681db.js"><link rel="prefetch" href="/blog/assets/js/174.5c66f092.js"><link rel="prefetch" href="/blog/assets/js/175.bbbdffbe.js"><link rel="prefetch" href="/blog/assets/js/176.262d26df.js"><link rel="prefetch" href="/blog/assets/js/177.e006c7d1.js"><link rel="prefetch" href="/blog/assets/js/178.8b7976a5.js"><link rel="prefetch" href="/blog/assets/js/179.cf34a2b2.js"><link rel="prefetch" href="/blog/assets/js/18.c338fe95.js"><link rel="prefetch" href="/blog/assets/js/180.d2a4e612.js"><link rel="prefetch" href="/blog/assets/js/181.9338fd07.js"><link rel="prefetch" href="/blog/assets/js/182.e83e4a62.js"><link rel="prefetch" href="/blog/assets/js/183.472c384f.js"><link rel="prefetch" href="/blog/assets/js/184.711e54a6.js"><link rel="prefetch" href="/blog/assets/js/185.20075148.js"><link rel="prefetch" href="/blog/assets/js/186.08c67f20.js"><link rel="prefetch" href="/blog/assets/js/187.0aa1cef8.js"><link rel="prefetch" href="/blog/assets/js/188.5d767d7a.js"><link rel="prefetch" href="/blog/assets/js/189.e8e2eb21.js"><link rel="prefetch" href="/blog/assets/js/19.6b963460.js"><link rel="prefetch" href="/blog/assets/js/190.8b557318.js"><link rel="prefetch" href="/blog/assets/js/191.3e6fdc4f.js"><link rel="prefetch" href="/blog/assets/js/192.99d6e1d8.js"><link rel="prefetch" href="/blog/assets/js/193.4ced091e.js"><link rel="prefetch" href="/blog/assets/js/194.4b375e2e.js"><link rel="prefetch" href="/blog/assets/js/195.003e3d67.js"><link rel="prefetch" href="/blog/assets/js/196.fe952fa6.js"><link rel="prefetch" href="/blog/assets/js/197.ff421a66.js"><link rel="prefetch" href="/blog/assets/js/198.628c2c1a.js"><link rel="prefetch" href="/blog/assets/js/199.89c4e586.js"><link rel="prefetch" href="/blog/assets/js/20.839dae41.js"><link rel="prefetch" href="/blog/assets/js/200.1d9f2ef9.js"><link rel="prefetch" href="/blog/assets/js/201.5ba078d9.js"><link rel="prefetch" href="/blog/assets/js/202.b49b23f4.js"><link rel="prefetch" href="/blog/assets/js/203.d88a03d9.js"><link rel="prefetch" href="/blog/assets/js/204.145e5762.js"><link rel="prefetch" href="/blog/assets/js/205.5a01e256.js"><link rel="prefetch" href="/blog/assets/js/206.5da6ab5c.js"><link rel="prefetch" href="/blog/assets/js/207.02a926dc.js"><link rel="prefetch" href="/blog/assets/js/208.40276146.js"><link rel="prefetch" href="/blog/assets/js/209.edc34975.js"><link rel="prefetch" href="/blog/assets/js/21.bd21bd29.js"><link rel="prefetch" href="/blog/assets/js/210.02e4ee2f.js"><link rel="prefetch" href="/blog/assets/js/211.0f8a9304.js"><link rel="prefetch" href="/blog/assets/js/212.9220dd3d.js"><link rel="prefetch" href="/blog/assets/js/213.89521ebd.js"><link rel="prefetch" href="/blog/assets/js/214.cd5ec468.js"><link rel="prefetch" href="/blog/assets/js/215.0084d772.js"><link rel="prefetch" href="/blog/assets/js/216.ebd468b9.js"><link rel="prefetch" href="/blog/assets/js/217.fac21407.js"><link rel="prefetch" href="/blog/assets/js/218.9793e19a.js"><link rel="prefetch" href="/blog/assets/js/219.c89175e9.js"><link rel="prefetch" href="/blog/assets/js/22.e6bcf65d.js"><link rel="prefetch" href="/blog/assets/js/220.d496e411.js"><link rel="prefetch" href="/blog/assets/js/221.07a9338a.js"><link rel="prefetch" href="/blog/assets/js/222.22bf261f.js"><link rel="prefetch" href="/blog/assets/js/223.b9c6a055.js"><link rel="prefetch" href="/blog/assets/js/224.e29550d2.js"><link rel="prefetch" href="/blog/assets/js/225.a406a2ff.js"><link rel="prefetch" href="/blog/assets/js/226.78192713.js"><link rel="prefetch" href="/blog/assets/js/227.900f2296.js"><link rel="prefetch" href="/blog/assets/js/228.7243da66.js"><link rel="prefetch" href="/blog/assets/js/229.009debcf.js"><link rel="prefetch" href="/blog/assets/js/23.ebbc3fd3.js"><link rel="prefetch" href="/blog/assets/js/230.109a1752.js"><link rel="prefetch" href="/blog/assets/js/231.55d62061.js"><link rel="prefetch" href="/blog/assets/js/232.049029b8.js"><link rel="prefetch" href="/blog/assets/js/233.42dfc185.js"><link rel="prefetch" href="/blog/assets/js/234.4dbf5d59.js"><link rel="prefetch" href="/blog/assets/js/235.f78274d9.js"><link rel="prefetch" href="/blog/assets/js/236.a2b61bec.js"><link rel="prefetch" href="/blog/assets/js/237.6ae31c88.js"><link rel="prefetch" href="/blog/assets/js/238.2f5c56ae.js"><link rel="prefetch" href="/blog/assets/js/239.506a4e9f.js"><link rel="prefetch" href="/blog/assets/js/24.19bd04ec.js"><link rel="prefetch" href="/blog/assets/js/25.b4de33d1.js"><link rel="prefetch" href="/blog/assets/js/26.d9940ceb.js"><link rel="prefetch" href="/blog/assets/js/27.83d848ee.js"><link rel="prefetch" href="/blog/assets/js/28.31289bac.js"><link rel="prefetch" href="/blog/assets/js/29.45af5621.js"><link rel="prefetch" href="/blog/assets/js/30.d5c08e66.js"><link rel="prefetch" href="/blog/assets/js/31.78e43a68.js"><link rel="prefetch" href="/blog/assets/js/32.53ca76ee.js"><link rel="prefetch" href="/blog/assets/js/33.081e8ef6.js"><link rel="prefetch" href="/blog/assets/js/34.cb1866c1.js"><link rel="prefetch" href="/blog/assets/js/35.dca9b927.js"><link rel="prefetch" href="/blog/assets/js/36.0cee37e8.js"><link rel="prefetch" href="/blog/assets/js/37.637acdf4.js"><link rel="prefetch" href="/blog/assets/js/38.6624bf02.js"><link rel="prefetch" href="/blog/assets/js/39.58eab309.js"><link rel="prefetch" href="/blog/assets/js/4.44654b1a.js"><link rel="prefetch" href="/blog/assets/js/40.00ca637c.js"><link rel="prefetch" href="/blog/assets/js/41.2b5e8c27.js"><link rel="prefetch" href="/blog/assets/js/42.350d128c.js"><link rel="prefetch" href="/blog/assets/js/43.871dce82.js"><link rel="prefetch" href="/blog/assets/js/44.6d89c3e1.js"><link rel="prefetch" href="/blog/assets/js/45.6e554c79.js"><link rel="prefetch" href="/blog/assets/js/46.d15a7dc0.js"><link rel="prefetch" href="/blog/assets/js/47.8d66ca97.js"><link rel="prefetch" href="/blog/assets/js/48.3c1102e1.js"><link rel="prefetch" href="/blog/assets/js/49.e17a3436.js"><link rel="prefetch" href="/blog/assets/js/5.88de390f.js"><link rel="prefetch" href="/blog/assets/js/50.451b1c8b.js"><link rel="prefetch" href="/blog/assets/js/51.3799fbac.js"><link rel="prefetch" href="/blog/assets/js/52.f3ef3b5e.js"><link rel="prefetch" href="/blog/assets/js/53.a6bacd25.js"><link rel="prefetch" href="/blog/assets/js/54.dbb7c9ab.js"><link rel="prefetch" href="/blog/assets/js/55.2562d0c8.js"><link rel="prefetch" href="/blog/assets/js/56.14ea4931.js"><link rel="prefetch" href="/blog/assets/js/57.268c586a.js"><link rel="prefetch" href="/blog/assets/js/58.88fed51b.js"><link rel="prefetch" href="/blog/assets/js/59.02b32879.js"><link rel="prefetch" href="/blog/assets/js/6.277038ca.js"><link rel="prefetch" href="/blog/assets/js/60.a27059ce.js"><link rel="prefetch" href="/blog/assets/js/61.39fb215e.js"><link rel="prefetch" href="/blog/assets/js/62.0210588e.js"><link rel="prefetch" href="/blog/assets/js/63.05521a18.js"><link rel="prefetch" href="/blog/assets/js/64.8aa613a8.js"><link rel="prefetch" href="/blog/assets/js/65.acfdd371.js"><link rel="prefetch" href="/blog/assets/js/66.cb805d9b.js"><link rel="prefetch" href="/blog/assets/js/67.39f85baa.js"><link rel="prefetch" href="/blog/assets/js/68.7f79766a.js"><link rel="prefetch" href="/blog/assets/js/69.fa8624bd.js"><link rel="prefetch" href="/blog/assets/js/7.474f8f8d.js"><link rel="prefetch" href="/blog/assets/js/70.1f3e978d.js"><link rel="prefetch" href="/blog/assets/js/71.13cd9358.js"><link rel="prefetch" href="/blog/assets/js/72.739b22a8.js"><link rel="prefetch" href="/blog/assets/js/73.95f69ae2.js"><link rel="prefetch" href="/blog/assets/js/74.b6624f6a.js"><link rel="prefetch" href="/blog/assets/js/75.b0d9aa06.js"><link rel="prefetch" href="/blog/assets/js/76.18ef5b96.js"><link rel="prefetch" href="/blog/assets/js/77.46f6e413.js"><link rel="prefetch" href="/blog/assets/js/78.aebd00ee.js"><link rel="prefetch" href="/blog/assets/js/79.1b784d15.js"><link rel="prefetch" href="/blog/assets/js/8.9428e7ee.js"><link rel="prefetch" href="/blog/assets/js/80.1f550d53.js"><link rel="prefetch" href="/blog/assets/js/81.101cc131.js"><link rel="prefetch" href="/blog/assets/js/82.077c8298.js"><link rel="prefetch" href="/blog/assets/js/83.2e375d11.js"><link rel="prefetch" href="/blog/assets/js/84.38102a34.js"><link rel="prefetch" href="/blog/assets/js/85.24532d6a.js"><link rel="prefetch" href="/blog/assets/js/86.1dabbf00.js"><link rel="prefetch" href="/blog/assets/js/87.9ae389e9.js"><link rel="prefetch" href="/blog/assets/js/88.10e8abd6.js"><link rel="prefetch" href="/blog/assets/js/89.187e5e16.js"><link rel="prefetch" href="/blog/assets/js/9.da143545.js"><link rel="prefetch" href="/blog/assets/js/90.96496e91.js"><link rel="prefetch" href="/blog/assets/js/91.e7933218.js"><link rel="prefetch" href="/blog/assets/js/92.5484868f.js"><link rel="prefetch" href="/blog/assets/js/93.c8ee75e3.js"><link rel="prefetch" href="/blog/assets/js/94.f70985e2.js"><link rel="prefetch" href="/blog/assets/js/95.3abe7fbe.js"><link rel="prefetch" href="/blog/assets/js/96.80e5a938.js"><link rel="prefetch" href="/blog/assets/js/97.1f5e5197.js"><link rel="prefetch" href="/blog/assets/js/98.e3a275c8.js"><link rel="prefetch" href="/blog/assets/js/99.d33bf89e.js">
- <link rel="stylesheet" href="/blog/assets/css/0.styles.cf8cd190.css">
- </head>
- <body class="theme-mode-light">
- <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><img src="/blog/img/logo.png" alt="彪哥博客" class="logo"> <span class="site-name can-hide">彪哥博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link">首页</a></div><div class="nav-item"><a href="http://fseller.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
- 个人游戏网站
- <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/blog/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>前端文章</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/blog/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/blog/note/javascript/" class="nav-link">《JavaScript教程》</a></li><li class="dropdown-subitem"><a href="/blog/note/js/" class="nav-link">《JavaScript高级程序设计》</a></li><li class="dropdown-subitem"><a href="/blog/note/es6/" class="nav-link">《ES6 教程》</a></li><li class="dropdown-subitem"><a href="/blog/note/vue/" class="nav-link">《Vue》</a></li><li class="dropdown-subitem"><a href="/blog/note/react/" class="nav-link">《React》</a></li><li class="dropdown-subitem"><a href="/blog/note/typescript-axios/" class="nav-link">《TypeScript 从零实现 axios》</a></li><li class="dropdown-subitem"><a href="/blog/note/git/" class="nav-link">《Git》</a></li><li class="dropdown-subitem"><a href="/blog/pages/51afd6/" class="nav-link">TypeScript</a></li><li class="dropdown-subitem"><a href="/blog/pages/4643cd/" class="nav-link">JS设计模式总结</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="页面" class="dropdown-title"><a href="/blog/ui/" class="link-title">页面</a> <span class="title" style="display:none;">页面</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/8309a5b876fc95e3/" class="nav-link">HTML</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/0a83b083bdf257cb/" class="nav-link">CSS</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术" class="dropdown-title"><a href="/blog/technology/" class="link-title">技术</a> <span class="title" style="display:none;">技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/9a7ee40fc232253e/" class="nav-link">技术文档</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/4c778760be26d8b3/" class="nav-link">GitHub技巧</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/117708e0af7f0bd9/" class="nav-link">Nodejs</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/41f87d890d0a02af/" class="nav-link">博客搭建</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><a href="/blog/more/" class="link-title">更多</a> <span class="title" style="display:none;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/baaa02/" class="nav-link">实用技巧</a></li><li class="dropdown-item"><!----> <a href="/blog/friends/" class="nav-link">友情链接</a></li></ul></div></div><div class="nav-item"><a href="/blog/about/" class="nav-link">关于</a></div><div class="nav-item"><a href="/blog/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/blog/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/blog/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/blog/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/heBody/blog" target="_blank" rel="noopener noreferrer" class="repo-link">
- GitHub
- <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://fastly.jsdelivr.net/gh/xugaoyi/image_store/blog/20200103123203.jpg"> <div class="blogger-info"><h3>彪哥</h3> <span>爱好前端</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link">首页</a></div><div class="nav-item"><a href="http://fseller.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
- 个人游戏网站
- <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/blog/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>前端文章</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/blog/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/blog/note/javascript/" class="nav-link">《JavaScript教程》</a></li><li class="dropdown-subitem"><a href="/blog/note/js/" class="nav-link">《JavaScript高级程序设计》</a></li><li class="dropdown-subitem"><a href="/blog/note/es6/" class="nav-link">《ES6 教程》</a></li><li class="dropdown-subitem"><a href="/blog/note/vue/" class="nav-link">《Vue》</a></li><li class="dropdown-subitem"><a href="/blog/note/react/" class="nav-link">《React》</a></li><li class="dropdown-subitem"><a href="/blog/note/typescript-axios/" class="nav-link">《TypeScript 从零实现 axios》</a></li><li class="dropdown-subitem"><a href="/blog/note/git/" class="nav-link">《Git》</a></li><li class="dropdown-subitem"><a href="/blog/pages/51afd6/" class="nav-link">TypeScript</a></li><li class="dropdown-subitem"><a href="/blog/pages/4643cd/" class="nav-link">JS设计模式总结</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="页面" class="dropdown-title"><a href="/blog/ui/" class="link-title">页面</a> <span class="title" style="display:none;">页面</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/8309a5b876fc95e3/" class="nav-link">HTML</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/0a83b083bdf257cb/" class="nav-link">CSS</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术" class="dropdown-title"><a href="/blog/technology/" class="link-title">技术</a> <span class="title" style="display:none;">技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/9a7ee40fc232253e/" class="nav-link">技术文档</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/4c778760be26d8b3/" class="nav-link">GitHub技巧</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/117708e0af7f0bd9/" class="nav-link">Nodejs</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/41f87d890d0a02af/" class="nav-link">博客搭建</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><a href="/blog/more/" class="link-title">更多</a> <span class="title" style="display:none;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/baaa02/" class="nav-link">实用技巧</a></li><li class="dropdown-item"><!----> <a href="/blog/friends/" class="nav-link">友情链接</a></li></ul></div></div><div class="nav-item"><a href="/blog/about/" class="nav-link">关于</a></div><div class="nav-item"><a href="/blog/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/blog/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/blog/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/blog/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/heBody/blog" target="_blank" rel="noopener noreferrer" class="repo-link">
- GitHub
- <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>手册</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>文档笔记</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blog/pages/635088/" aria-current="page" class="active sidebar-link">Git基础与命令</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/blog/pages/635088/#git基础" class="sidebar-link">Git基础</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#全局配置" class="sidebar-link">全局配置</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#检查配置信息" class="sidebar-link">检查配置信息</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#获取帮助" class="sidebar-link">获取帮助</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#初始化仓库" class="sidebar-link">初始化仓库</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#克隆远程仓库" class="sidebar-link">克隆远程仓库</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#检查文件状态" class="sidebar-link">检查文件状态</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#加入暂存区-跟踪文件" class="sidebar-link">加入暂存区 (跟踪文件)</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#忽略文件" class="sidebar-link">忽略文件</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#查看修改的具体内容" class="sidebar-link">查看修改的具体内容</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#提交更新" class="sidebar-link">提交更新</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#跳过使用暂存区域" class="sidebar-link">跳过使用暂存区域</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/blog/pages/635088/#git-基础-查看提交历史" class="sidebar-link">Git 基础 - 查看提交历史</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/635088/#git-基础-撤消操作" class="sidebar-link">Git 基础 - 撤消操作</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/635088/#git-基础-远程仓库的使用" class="sidebar-link">Git 基础 - 远程仓库的使用</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#查看远程仓库" class="sidebar-link">查看远程仓库</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#添加远程仓库" class="sidebar-link">添加远程仓库</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#从远程仓库中抓取与拉取" class="sidebar-link">从远程仓库中抓取与拉取</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#推送到远程仓库" class="sidebar-link">推送到远程仓库</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#查看某个远程仓库" class="sidebar-link">查看某个远程仓库</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#远程仓库的重命名与移除" class="sidebar-link">远程仓库的重命名与移除</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/blog/pages/635088/#git-基础-打标签" class="sidebar-link">Git 基础 - 打标签</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#列出标签" class="sidebar-link">列出标签</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#创建标签" class="sidebar-link">创建标签</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#附注标签" class="sidebar-link">附注标签</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#轻量标签" class="sidebar-link">轻量标签</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#后期打标签" class="sidebar-link">后期打标签</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#共享标签" class="sidebar-link">共享标签</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#删除标签" class="sidebar-link">删除标签</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/635088/#检出标签" class="sidebar-link">检出标签</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/blog/pages/635088/#git-命令别名" class="sidebar-link">Git 命令别名</a></li></ul></li><li><a href="/blog/pages/4bef1a/" class="sidebar-link">Git分支-分支原理</a></li><li><a href="/blog/pages/ea5a8c/" class="sidebar-link">Git分支的新建与合并-分支操作</a></li><li><a href="/blog/pages/a399b3/" class="sidebar-link">Git分支管理-查看分支</a></li><li><a href="/blog/pages/49ee30/" class="sidebar-link">Git分支开发工作流</a></li><li><a href="/blog/pages/574d62/" class="sidebar-link">Git分支-远程分支</a></li><li><a href="/blog/pages/3a3247/" class="sidebar-link">Git分支-变基</a></li><li><a href="/blog/pages/c984d1/" class="sidebar-link">Git工具-查看修订版本</a></li><li><a href="/blog/pages/76d859/" class="sidebar-link">Git工具-交互式暂存</a></li><li><a href="/blog/pages/1832fe/" class="sidebar-link">Git工具-重写历史</a></li><li><a href="/blog/pages/d9e9c6/" class="sidebar-link">Git工具-重置揭密</a></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06970110><div class="articleInfo" data-v-06970110><ul class="breadcrumbs" data-v-06970110><li data-v-06970110><a href="/blog/" title="首页" class="iconfont icon-home router-link-active" data-v-06970110></a></li> <li data-v-06970110><a href="/blog/note/git/#《Git》学习笔记" data-v-06970110>《Git》学习笔记</a></li><li data-v-06970110><a href="/blog/note/git/#文档笔记" data-v-06970110>文档笔记</a></li></ul> <div class="info" data-v-06970110><div title="作者" class="author iconfont icon-touxiang" data-v-06970110><a href="https://github.com/heBody" target="_blank" title="作者" class="beLink" data-v-06970110>heBody</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06970110><a href="javascript:;" data-v-06970110>2020-11-18</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAABGpJREFUSA3tVVtoXFUU3fvOI53UlmCaKIFmwEhsE7QK0ipFEdHEKpXaZGrp15SINsXUWvBDpBgQRKi0+KKoFeJHfZA+ED9KKoIU2gYD9UejTW4rVIzm0VSTziPzuNu1z507dibTTjL4U/DAzLn3nL3X2o91ziX6f9wMFdh6Jvbm9nNSV0msViVO6tN1Rm7NMu2OpeJ9lWBUTDxrJbYTS0hInuwciu9eLHlFxCLCZEk3MegsJmZ5K/JD6t7FkFdEvGUo1g7qJoG3MHImqRIn8/nzY1K9UPKKiJmtnUqHVE3Gbuay6vJE/N2FEmuxFjW2nUuE0yQXRRxLiTUAzs36zhZvOXJPdX850EVnnLZkB8prodQoM5JGj7Xk2mvC7JB8tG04Ef5PiXtG0UtxupRQSfTnBoCy554x18yJHI6I+G5Eru4LHmPJZEQsrvPUbMiA8G/WgMK7w7I+ez7++o2ANfbrjvaOl1tFMs+htG3IrZH9/hDX1Pr8Tc0UvH8tcX29KzAgIGcEkINyW5BF9x891hw6VYqgJHEk0huccS7vh3C6gTiODL+26huuBtbct8eZnqLML8PkxGYpuPZBqtqwkSjgc4mB5gbgig5i+y0UDK35LMxXisn9xQtK+nd26gTIHsHe/oblK/b29fUmN/8Y+9jAQrnBp56m1LcDlDp9irKTExSKduXJVWSqdBMA08pEJnEIOB3FPPMybu/oeV8zFeYN3xx576Q6RH+VmplE4ncQV5v+5rzSoyOU7PuEAg8g803PwBJ0CExno/jcMbN8tONYeOmHiuUNryvm3fRUy4tMPVLdAGkUhNWuggGrJcXPv+ouCjz0MKUHz1J2/E8IC9nqTabcxgaBYM0hPhD5Y65FsbxRQKxCQrDjDctW7PUM3HuZunFyifSAqEfuzCp48Il24luWUWZoyJCaPR82jE0+kFA643wRFVni4RYSq3ohJO2pZ7B5dO4xkDWbEpossJPLSrPjYID8rS2UHTlvyNxqIGsg674XJJ7vnh5L7PNwC4hh2sjCI96mzszOTpxLF0T7l88Yz7lAuK6OnL8gXLOnTvpzSb22YG8W7us3jSebFHeeqnXRG1vt+MoUM84LQIBmMsCTAcOauTh0T0l0neQK7m2bLMt2mGxU3HYssS0J2cdv5wljlPsrIuZLAG/2DOZIXgCYT8uMGZN+e2kSirfxZOPCsC0f24nTZzspnVn9VePS1Z5vubmAGGXG8ZFno9Hel0yfA5ZPhF7Dh972BQJ2qCpgH67lmWtBYbvk6sz02wjky2vXyz0XErP/kFB619js1BtwfOV4OPRqOQBjy3Qbk18vigUPPSD5ceHnwck7W9bhAqZdd7SuG7w4/P2F/GaJh8c7e9qgow+Q7cGBo+98WsLkuktFqiZabtXuQTu/Y5ETbR0v7tNSFnvrmu6pjdoan2KjMu8q/Hmj1EfCO2ZGfEIbIXKUlw8qaX9/b2oeSJmFksSeT/Fn0V3nSypChh4Gjh74ybO9aeZ/AN2dwciu2/MhAAAAAElFTkSuQmCC">Git基础与命令<!----></h1> <div class="theme-vdoing-content content__default"><h1 id="git基础与命令"><a href="#git基础与命令" class="header-anchor">#</a> Git基础与命令</h1> <p>官方文档(中文):https://git-scm.com/book/zh/v2</p> <blockquote><p>本文档是根据官方文档来编写的,以官方文档为准。</p></blockquote> <h2 id="git基础"><a href="#git基础" class="header-anchor">#</a> Git基础</h2> <h3 id="全局配置"><a href="#全局配置" class="header-anchor">#</a> 全局配置</h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> config <span class="token parameter variable">--global</span> user.name <span class="token string">'your name'</span>
- <span class="token function">git</span> config <span class="token parameter variable">--global</span> user.email <span class="token string">'xxx@xx.com'</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>自报家门</p> <h3 id="检查配置信息"><a href="#检查配置信息" class="header-anchor">#</a> 检查配置信息</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> config <span class="token parameter variable">--list</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="获取帮助"><a href="#获取帮助" class="header-anchor">#</a> 获取帮助</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 获取全局帮助手册</span>
- <span class="token function">git</span> <span class="token builtin class-name">help</span>
- <span class="token comment"># 获取特定命令的详细版帮助手册 (两个命令是等价的)</span>
- <span class="token function">git</span> <span class="token builtin class-name">help</span> <span class="token operator"><</span>某个命令<span class="token operator">></span>
- <span class="token function">git</span> <span class="token operator"><</span>某个命令<span class="token operator">></span> <span class="token parameter variable">--help</span> <span class="token comment"># 两个横杠</span>
- <span class="token comment"># 获取特定命令的简明版帮助手册</span>
- <span class="token function">git</span> <span class="token operator"><</span>某个命令<span class="token operator">></span> <span class="token parameter variable">-h</span> <span class="token comment"># 一个横杠</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="初始化仓库"><a href="#初始化仓库" class="header-anchor">#</a> 初始化仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 本地目录初始化仓库</span>
- <span class="token function">git</span> init
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>如果你是从远程仓库clone的项目,则该项目是已经初始化好的git仓库</p> <h3 id="克隆远程仓库"><a href="#克隆远程仓库" class="header-anchor">#</a> 克隆远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 克隆</span>
- <span class="token function">git</span> clone <span class="token operator"><</span>url<span class="token operator">></span>
- <span class="token comment"># 克隆同时修改目录名</span>
- <span class="token function">git</span> clone <span class="token operator"><</span>url<span class="token operator">></span> <span class="token operator"><</span>name<span class="token operator">></span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>初次克隆某个仓库的时候,工作目录中的所有文件都属于已跟踪文件,并处于未修改状态,因为 Git 刚刚检出了它们, 而你尚未编辑过它们</p> <h3 id="检查文件状态"><a href="#检查文件状态" class="header-anchor">#</a> 检查文件状态</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 查看详细状态说明</span>
- <span class="token function">git</span> status
- <span class="token comment"># 查看简明状态说明</span>
- <span class="token function">git</span> status <span class="token parameter variable">-s</span> <span class="token comment"># -s 或 --short</span>
- M README <span class="token comment"># 已修改,但未暂存 (M的位置靠右,红色)</span>
- MM Rakefile <span class="token comment"># 已修改,暂存后又作了修改(有暂存和未暂存)</span>
- A lib/git.rb <span class="token comment"># 新添加到暂存区,未提交</span>
- M lib/simplegit.rb <span class="token comment"># 已修改,已暂存 (M的位置靠左,绿色)</span>
- ?? LICENSE.txt <span class="token comment"># 新添加,未跟踪</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><ul><li><p>git目录中的文件状态包含:是否跟踪、是否修改、是否已存入暂存区</p></li> <li><p>参数的<strong>一个横杠表示缩写,两个横杠表示全称。</strong></p></li></ul> <h3 id="加入暂存区-跟踪文件"><a href="#加入暂存区-跟踪文件" class="header-anchor">#</a> 加入暂存区 (跟踪文件)</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 文件加入暂存区(跟踪指定文件)</span>
- <span class="token function">git</span> <span class="token function">add</span> <span class="token operator"><</span>files<span class="token operator">></span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><code>git add</code> 命令使用文件或目录的路径作为参数;如果参数是目录的路径,该命令将递归地跟踪该目录下的所有文件。</p> <p><code>add</code> 命令是将文件<strong>加入</strong>到<strong>暂存区</strong>,<code>commit</code> 命令的<strong>提交</strong>到<strong>本地仓库</strong>,<code>push</code> 命令是<strong>推送</strong>到<strong>远程仓库</strong>。</p> <h3 id="忽略文件"><a href="#忽略文件" class="header-anchor">#</a> 忽略文件</h3> <p>添加一个名为 <code>.gitignore</code> 的文件,列出要忽略的文件的模式</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>*.<span class="token punctuation">[</span>oa<span class="token punctuation">]</span> <span class="token comment"># 忽略以 .o 或 .a 结尾的文件(一般这类文件是编译过程出现)</span>
- *~ <span class="token comment"># 忽略以 ~ 结尾的文件(一般是文本编辑软件保存的副本)</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>文件 <code>.gitignore</code> 的<strong>格式规范</strong>如下:</p> <ul><li><p>所有空行或者以 <code>#</code> 开头的行都会被 Git 忽略(注释符号)。</p></li> <li><p>可以使用标准的 glob 模式匹配,它会递归地应用在整个工作区中。</p> <blockquote><p>glob 模式是指 shell 所使用的简化了的正则表达式</p></blockquote></li> <li><p>匹配模式可以以(<code>/</code>)开头防止递归。</p></li> <li><p>匹配模式可以以(<code>/</code>)结尾指定目录。</p></li> <li><p>要忽略指定模式以外的文件或目录,可以在模式前加上叹号(<code>!</code>)取反。</p></li></ul> <hr> <ul><li>星号(<code>*</code>)匹配零个或多个任意字符</li> <li><code>[abc]</code> 匹配任何一个列在方括号中的字符 (这个例子要么匹配一个 a,要么匹配一个 b,要么匹配一个 c)</li> <li>问号(<code>?</code>)只匹配一个任意字符</li> <li><code>[0-9]</code> 表示匹配所有 0 到 9 的数字。在方括号中使用短划线分隔两个字符, 表示所有在这两个字符范围内的都可以匹配</li> <li>使用两个星号(<code>**</code>)表示匹配任意中间目录,比如 <code>a/**/z</code> 可以匹配 <code>a/z</code> 、 <code>a/b/z</code> 或 <code>a/b/c/z</code> 等。</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 忽略所有的 .a 文件</span>
- *.a
- <span class="token comment"># 但跟踪所有的 lib.a,即便你在前面忽略了 .a 文件</span>
- <span class="token operator">!</span>lib.a
- <span class="token comment"># 只忽略当前目录下的 TODO 文件,而不忽略 subdir/TODO</span>
- /TODO
- <span class="token comment"># 忽略任何目录下名为 build 的文件夹</span>
- build/
- <span class="token comment"># 忽略 doc/notes.txt,但不忽略 doc/server/arch.txt</span>
- doc/*.txt
- <span class="token comment"># 忽略 doc/ 目录及其所有子目录下的 .pdf 文件</span>
- doc/**/*.pdf
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>GitHub 有一个十分详细的针对数十种项目及语言的 <code>.gitignore</code> 文件列表, 你可以在 https://github.com/github/gitignore 找到它。</p> <h3 id="查看修改的具体内容"><a href="#查看修改的具体内容" class="header-anchor">#</a> 查看修改的具体内容</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> <span class="token function">diff</span> <span class="token comment"># 比较修改之后还没有暂存起来的变化内容。</span>
- <span class="token function">git</span> <span class="token function">diff</span> <span class="token parameter variable">--staged</span> <span class="token comment"># 查看已暂存的将要添加到下次提交里的内容</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><code>git status</code> 只能查看文件变动的状态,并不能查看具体修改了哪些内容。使用<code>git diff</code>可以看到具体变动的内容。</p> <h3 id="提交更新"><a href="#提交更新" class="header-anchor">#</a> 提交更新</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> commit <span class="token comment"># 未带参数的会打开默认文本编辑器让你输入提交说明</span>
- <span class="token function">git</span> commit <span class="token parameter variable">-m</span> <span class="token string">'提交说明'</span> <span class="token comment"># 带-m参数直接输入提交说明</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>使用<code>git commit</code>提交更新,在此之前,务必确认所有变动已经被<code>git add</code>添加到暂存区。</p> <h3 id="跳过使用暂存区域"><a href="#跳过使用暂存区域" class="header-anchor">#</a> 跳过使用暂存区域</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><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">'提交说明'</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>添加<code>-a</code>选项可以跳过<code>git add</code> 步骤,把已经跟踪过的文件一并提交。</p> <p>注意:这个操作<strong>无法提交未跟踪</strong>的文件。</p> <h2 id="git-基础-查看提交历史"><a href="#git-基础-查看提交历史" class="header-anchor">#</a> Git 基础 - 查看提交历史</h2> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> log
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>不传入任何参数的默认情况下,<code>git log</code> 会按时间先后顺序列出所有的提交,最近的更新排在最上面。</p> <p>此命令打印的数据中有一项是一长串的 <code>SHA-1</code> 校验码。</p> <p><strong>带入<code>-p</code>或<code>--patch</code>查看提交的具体差异:</strong></p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> log <span class="token parameter variable">-p</span> <span class="token parameter variable">-2</span> <span class="token comment"># -p显示差异 -2显示最近的提交次数</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><code>--stat</code> 显示每次提交的差异统计</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> log <span class="token parameter variable">--stat</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><code>--pretty</code> 这个选项可以使用不同于默认格式的方式展示提交历史</p> <p>这个选项有一些内建的子选项供你使用。 比如 <code>oneline</code> 会将每个提交放在一行显示,在浏览大量的提交时非常有用。 另外还有 <code>short</code>,<code>full</code> 和 <code>fuller</code> 选项,它们展示信息的格式基本一致,但是详尽程度不一:</p> <div class="language-fsharp line-numbers-mode"><pre class="language-fsharp"><code>$ git log <span class="token operator">-</span><span class="token operator">-</span>pretty<span class="token operator">=</span>oneline
- ca82a6dff817ec66f44342007202690a93763949 changed the version number
- 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test
- a11bef06a3f659402fe7563abf99ad00de2209e6 first commit
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>最有意思的是 <code>format</code> ,可以定制记录的显示格式。 这样的输出对后期提取分析格外有用——因为你知道输出的格式不会随着 Git 的更新而发生改变:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> log <span class="token parameter variable">--pretty</span><span class="token operator">=</span>format:<span class="token string">"%h - %an, %ar : %s"</span>
- ca82a6d - Scott Chacon, <span class="token number">6</span> years ago <span class="token builtin class-name">:</span> changed the version number
- 085bb3b - Scott Chacon, <span class="token number">6</span> years ago <span class="token builtin class-name">:</span> removed unnecessary <span class="token builtin class-name">test</span>
- a11bef0 - Scott Chacon, <span class="token number">6</span> years ago <span class="token builtin class-name">:</span> first commit
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><a href="https://git-scm.com/book/zh/v2/ch00/pretty_format" target="_blank" rel="noopener noreferrer"><code>git log --pretty=format</code> 常用的选项<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 列出了 <code>format</code> 接受的常用格式占位符的写法及其代表的意义。</p> <p><strong>当 <code>oneline</code> 或 <code>format</code> 与另一个 <code>log</code> 选项 <code>--graph</code> 结合使用时尤其有用。 这个选项添加了一些 ASCII 字符串来形象地展示你的分支、合并历史:</strong></p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> log <span class="token parameter variable">--pretty</span><span class="token operator">=</span>format:<span class="token string">"%h %s"</span> <span class="token parameter variable">--graph</span>
- * 2d3acf9 ignore errors from SIGCHLD on <span class="token builtin class-name">trap</span>
- * 5e3ee11 Merge branch <span class="token string">'master'</span> of git://github.com/dustin/grit
- <span class="token operator">|</span><span class="token punctuation">\</span>
- <span class="token operator">|</span> * 420eac9 Added a method <span class="token keyword">for</span> getting the current branch.
- * <span class="token operator">|</span> 30e367c <span class="token function">timeout</span> code and tests
- * <span class="token operator">|</span> 5a09431 <span class="token function">add</span> <span class="token function">timeout</span> protection to grit
- * <span class="token operator">|</span> e1193f8 support <span class="token keyword">for</span> heads with slashes <span class="token keyword">in</span> them
- <span class="token operator">|</span>/
- * d6016bc require <span class="token function">time</span> <span class="token keyword">for</span> xmlschema
- * 11d191e Merge branch <span class="token string">'defunkt'</span> into <span class="token builtin class-name">local</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h2 id="git-基础-撤消操作"><a href="#git-基础-撤消操作" class="header-anchor">#</a> Git 基础 - 撤消操作</h2> <p>你提交后发现忘记了暂存某些需要的修改,可以像下面这样操作:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> commit <span class="token parameter variable">-m</span> <span class="token string">'initial commit'</span>
- $ <span class="token function">git</span> <span class="token function">add</span> forgotten_file
- $ <span class="token function">git</span> commit <span class="token parameter variable">--amend</span> <span class="token comment"># 重新提交,且只有一次提交记录</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>最终你只会有一个提交——第二次提交将代替第一次提交的结果。</p> <p>更多撤销操作请了解 <code>reset</code>命令。</p> <h2 id="git-基础-远程仓库的使用"><a href="#git-基础-远程仓库的使用" class="header-anchor">#</a> Git 基础 - 远程仓库的使用</h2> <h3 id="查看远程仓库"><a href="#查看远程仓库" class="header-anchor">#</a> 查看远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> remote <span class="token comment"># 仅显示远程仓库的名称</span>
- <span class="token function">git</span> remote <span class="token parameter variable">-v</span> <span class="token comment"># 显示远程仓库的名称 + 地址</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="添加远程仓库"><a href="#添加远程仓库" class="header-anchor">#</a> 添加远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code> <span class="token function">git</span> remote <span class="token function">add</span> <span class="token operator"><</span>远程仓库名<span class="token operator">></span> <span class="token operator"><</span>url<span class="token operator">></span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="从远程仓库中抓取与拉取"><a href="#从远程仓库中抓取与拉取" class="header-anchor">#</a> 从远程仓库中抓取与拉取</h3> <p>就如刚才所见,从远程仓库中获得数据,可以执行:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> fetch <span class="token operator"><</span>remote<span class="token operator">></span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这个命令会访问远程仓库,从中拉取所有你还没有的数据。 执行完成后,你将会拥有那个远程仓库中所有分支的引用,可以随时合并或查看。</p> <p>注意: <code>git fetch</code> 命令只会将数据下载到你的本地仓库——<strong>它并不会自动合并或修改你当前的工作</strong>。 当准备好时你必须手动将其合并入你的工作。</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> pull
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>用 <code>git pull</code> 命令来自动抓取后合并该远程分支到当前分支。 这或许是个更加简单舒服的工作流程。默认情况下,<code>git clone</code> 命令会自动设置本地 master 分支跟踪克隆的远程仓库的 <code>master</code> 分支(或其它名字的默认分支)。 <strong>运行 <code>git pull</code> 通常会从最初克隆的服务器上抓取数据并自动尝试合并到当前所在的分支。</strong></p> <h3 id="推送到远程仓库"><a href="#推送到远程仓库" class="header-anchor">#</a> 推送到远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> push <span class="token operator"><</span>remote<span class="token operator">></span> <span class="token operator"><</span>branch<span class="token operator">></span> <span class="token comment"># git push origin master</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="查看某个远程仓库"><a href="#查看某个远程仓库" class="header-anchor">#</a> 查看某个远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code> <span class="token function">git</span> remote show <span class="token operator"><</span>remote<span class="token operator">></span> <span class="token comment"># git remote show origin</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>查看远程仓库的详细信息。这个命令列出了当你在特定的分支上执行 <code>git push</code> 会自动地推送到哪一个远程分支</p> <h3 id="远程仓库的重命名与移除"><a href="#远程仓库的重命名与移除" class="header-anchor">#</a> 远程仓库的重命名与移除</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> remote <span class="token function">rename</span> <span class="token operator"><</span>原名<span class="token operator">></span> <span class="token operator"><</span>新名<span class="token operator">></span> <span class="token comment"># 重命名</span>
- <span class="token function">git</span> remote remove paul <span class="token operator"><</span>remote<span class="token operator">></span><span class="token comment"># 移除远程仓库</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="git-基础-打标签"><a href="#git-基础-打标签" class="header-anchor">#</a> Git 基础 - 打标签</h2> <h3 id="列出标签"><a href="#列出标签" class="header-anchor">#</a> 列出标签</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> tag <span class="token comment"># 完整标签列表</span>
- <span class="token function">git</span> tag <span class="token parameter variable">-l</span> <span class="token string">"v2.0*"</span> <span class="token comment"># 只显示包含 v2.0 的标签。 注意加星号(*)</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><code>-l</code> 或 <code>--list</code> 都可以。</p> <h3 id="创建标签"><a href="#创建标签" class="header-anchor">#</a> 创建标签</h3> <p>Git 支持两种标签:<strong>轻量标签</strong>(lightweight)与<strong>附注标签</strong>(annotated)。</p> <p>轻量标签很像一个不会改变的分支——它<strong>只是某个特定提交的引用</strong>。</p> <p>而附注标签是存储在 Git 数据库中的一个完整对象, 它们是可以被校验的,其中<strong>包含打标签者的名字、电子邮件地址、日期时间, 此外还有一个标签信息</strong>,并且可以使用 GNU Privacy Guard (GPG)签名并验证。 通常会建议创建附注标签,这样你可以拥有以上所有信息。但是如果你只是想用一个临时的标签, 或者因为某些原因不想要保存这些信息,那么也可以用轻量标签。</p> <h3 id="附注标签"><a href="#附注标签" class="header-anchor">#</a> 附注标签</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> tag <span class="token parameter variable">-a</span> v1.4 <span class="token parameter variable">-m</span> <span class="token string">"my version 1.4"</span> <span class="token comment"># -a表示add, -m 表示附件信息</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>通过使用 <code>git show</code> 命令可以看到标签信息和与之对应的提交信息:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> show v1.4
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="轻量标签"><a href="#轻量标签" class="header-anchor">#</a> 轻量标签</h3> <p>轻量标签本质上是将提交校验和存储到一个文件中——没有保存任何其他信息。 创建轻量标签,不需要使用 <code>-a</code>、<code>-s</code> 或 <code>-m</code> 选项,只需要提供标签名字:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> tag v1.4-lw <span class="token comment"># 不需要添加选项</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这时,如果在标签上运行 <code>git show</code>,你不会看到额外的标签信息。 命令只会显示出提交信息:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> show v1.4-lw
- commit ca82a6dff817ec66f44342007202690a93763949
- Author: Scott Chacon <span class="token operator"><</span>schacon@gee-mail.com<span class="token operator">></span>
- Date: Mon Mar <span class="token number">17</span> <span class="token number">21</span>:52:11 <span class="token number">2008</span> <span class="token parameter variable">-0700</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="后期打标签"><a href="#后期打标签" class="header-anchor">#</a> 后期打标签</h3> <p>你也可以对过去的提交打标签。 假设提交历史是这样的:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> log <span class="token parameter variable">--pretty</span><span class="token operator">=</span>oneline
- 166ae0c4d3f420721acbb115cc33848dfcc2121a started <span class="token function">write</span> support
- 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
- 8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>现在,假设在 v1.2 时你忘记给项目打标签,也就是在 “updated rakefile” 提交。 你可以在之后补上标签。 要在那个提交上打标签,你需要在命令的末尾指定提交的校验和(或部分校验和):</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> tag <span class="token parameter variable">-a</span> v1.2 9fceb02 <span class="token comment"># 打的标签属于附注标签</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="共享标签"><a href="#共享标签" class="header-anchor">#</a> 共享标签</h3> <p><code>git push</code> 命令并不会传送标签到远程仓库服务器上。 在创建完标签后你必须显式地推送标签到共享服务器上。 这个过程就像共享远程分支一样——你可以运行 <code>git push origin <tagname></code>。</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> push origin v1.5 <span class="token comment"># 显式地推送标签到远程仓库</span>
- <span class="token function">git</span> push origin <span class="token parameter variable">--tags</span> <span class="token comment"># 一次性推送所有不在远程仓库上的标签</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>现在,当其他人从仓库中克隆或拉取,他们也能得到你的那些标签。</p> <h3 id="删除标签"><a href="#删除标签" class="header-anchor">#</a> 删除标签</h3> <p>要删除掉你本地仓库上的标签,可以使用命令 <code>git tag -d <tagname></code>。 例如,可以使用以下命令删除一个轻量标签:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> tag <span class="token parameter variable">-d</span> v1.4-lw
- Deleted tag <span class="token string">'v1.4-lw'</span> <span class="token punctuation">(</span>was e7d5add<span class="token punctuation">)</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>注意上述命令并不会从任何远程仓库中移除这个标签,你必须用 <code>git push <remote> :refs/tags/<tagname></code> 来更新你的远程仓库:</p> <p>第一种变体是 <code>git push <remote> :refs/tags/<tagname></code> :</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> push origin :refs/tags/v1.4-lw
- To /git@github.com:schacon/simplegit.git
- - <span class="token punctuation">[</span>deleted<span class="token punctuation">]</span> v1.4-lw
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>上面这种操作的含义是,将冒号前面的空值推送到远程标签名,从而高效地删除它。</p> <p>第二种更直观的删除远程标签的方式是:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> push origin <span class="token parameter variable">--delete</span> <span class="token operator"><</span>tagname<span class="token operator">></span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="检出标签"><a href="#检出标签" class="header-anchor">#</a> 检出标签</h3> <p>如果你想查看某个标签所指向的文件版本,可以使用 <code>git checkout</code> 命令, 虽然这会使你的仓库处于“分离头指针(detached HEAD)”的状态——这个状态有些不好的副作用:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> checkout <span class="token number">2.0</span>.0
- Note: checking out <span class="token string">'2.0.0'</span><span class="token builtin class-name">.</span>
- You are <span class="token keyword">in</span> <span class="token string">'detached HEAD'</span> state. You can <span class="token function">look</span> around, <span class="token function">make</span> experimental
- changes and commit them, and you can discard any commits you <span class="token function">make</span> <span class="token keyword">in</span> this
- state without impacting any branches by performing another checkout.
- If you want to create a new branch to retain commits you create, you may
- <span class="token keyword">do</span> so <span class="token punctuation">(</span>now or later<span class="token punctuation">)</span> by using <span class="token parameter variable">-b</span> with the checkout <span class="token builtin class-name">command</span> again. Example:
- <span class="token function">git</span> checkout <span class="token parameter variable">-b</span> <span class="token operator"><</span>new-branch<span class="token operator">></span>
- HEAD is now at 99ada87<span class="token punctuation">..</span>. Merge pull request <span class="token comment">#89 from schacon/appendix-final</span>
- $ <span class="token function">git</span> checkout <span class="token number">2.0</span>-beta-0.1
- Previous HEAD position was 99ada87<span class="token punctuation">..</span>. Merge pull request <span class="token comment">#89 from schacon/appendix-final</span>
- HEAD is now at df3f601<span class="token punctuation">..</span>. <span class="token function">add</span> atlas.json and cover image
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>在“分离头指针”状态下,如果你做了某些更改然后提交它们,标签不会发生变化, 但你的新提交将不属于任何分支,并且将无法访问,除非通过确切的提交哈希才能访问。 因此,如果你需要进行更改,比如你要修复旧版本中的错误,那么通常需要创建一个新分支:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> checkout <span class="token parameter variable">-b</span> version2 v2.0.0
- Switched to a new branch <span class="token string">'version2'</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>如果在这之后又进行了一次提交,<code>version2</code> 分支就会因为这个改动向前移动, 此时它就会和 <code>v2.0.0</code> 标签稍微有些不同,这时就要当心了。</p> <h2 id="git-命令别名"><a href="#git-命令别名" class="header-anchor">#</a> Git 命令别名</h2> <p>Git 并不会在你输入部分命令时自动推断出你想要的命令。 如果不想每次都输入完整的 Git 命令,可以通过 <code>git config</code> 文件来轻松地为每一个命令设置一个别名。 这里有一些例子你可以试试:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> config <span class="token parameter variable">--global</span> alias.co checkout
- $ <span class="token function">git</span> config <span class="token parameter variable">--global</span> alias.br branch
- $ <span class="token function">git</span> config <span class="token parameter variable">--global</span> alias.ci commit
- $ <span class="token function">git</span> config <span class="token parameter variable">--global</span> alias.st status
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>这意味着,当要输入 <code>git commit</code> 时,只需要输入 <code>git ci</code>。</p> <p>在创建你认为应该存在的命令时这个技术会很有用。 例如,为了解决取消暂存文件的易用性问题,可以向 Git 中添加你自己的取消暂存别名:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> config <span class="token parameter variable">--global</span> alias.unstage <span class="token string">'reset HEAD --'</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这会使下面的两个命令等价:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> unstage fileA
- $ <span class="token function">git</span> reset HEAD -- fileA
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>这样看起来更清楚一些。 通常也会添加一个 <code>last</code> 命令,像这样:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> config <span class="token parameter variable">--global</span> alias.last <span class="token string">'log -1 HEAD'</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这样,可以轻松地看到最后一次提交:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> last
- commit 66938dae3329c7aebe598c2246a8e6af90d04646
- Author: Josh Goebel <span class="token operator"><</span>dreamer3@example.com<span class="token operator">></span>
- Date: Tue Aug <span class="token number">26</span> <span class="token number">19</span>:48:51 <span class="token number">2008</span> +0800
- <span class="token builtin class-name">test</span> <span class="token keyword">for</span> current <span class="token function">head</span>
- Signed-off-by: Scott Chacon <span class="token operator"><</span>schacon@example.com<span class="token operator">></span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>可以看出,Git 只是简单地将别名替换为对应的命令。 然而,你可能想要执行外部命令,而不是一个 Git 子命令。 如果是那样的话,可以在命令前面加入 <code>!</code> 符号。 如果你自己要写一些与 Git 仓库协作的工具的话,那会很有用。 我们现在演示将 <code>git visual</code> 定义为 <code>gitk</code> 的别名:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> config <span class="token parameter variable">--global</span> alias.visual <span class="token string">'!gitk'</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></div></div> <div class="page-edit"><div class="edit-link"><a href="https://github.com/heBody/blog/edit/master/docs/《Git》学习笔记/20.文档笔记/10.Git基础与命令.md" target="_blank" rel="noopener noreferrer">编辑</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="tags"><a href="/blog/tags/?tag=Git" title="标签">#Git</a></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2022/12/14, 19:36:42</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/blog/pages/4cbc21/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">Git命令思维导图</div></a> <a href="/blog/pages/4bef1a/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">Git分支-分支原理</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
- ←
- <a href="/blog/pages/4cbc21/" class="prev">Git命令思维导图</a></span> <span class="next"><a href="/blog/pages/4bef1a/">Git分支-分支原理</a>→
- </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/blog/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/blog/pages/922650/"><div>
- Git修改分支名
- <!----></div></a> <span class="date">08-11</span></dt></dl><dl><dd>02</dd> <dt><a href="/blog/pages/55f894/"><div>
- CSS给table的tbody添加滚动条
- <!----></div></a> <span class="date">06-29</span></dt></dl><dl><dd>03</dd> <dt><a href="/blog/pages/829589/"><div>
- 我做了一个手写春联小网页,祝大家虎年暴富
- <span class="title-tag">
- 原创
- </span></div></a> <span class="date">01-28</span></dt></dl> <dl><dd></dd> <dt><a href="/blog/archives/" class="more">更多文章></a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:30363811@qq.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/heBody" title="GitHub" target="_blank" class="iconfont icon-github"></a></div>
- Copyright © 2016-2022
- <span>Hesb | <a href="https://github.com/heBody/blob" target="_blank">MIT License</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
- 跟随系统
- </li><li class="iconfont icon-rijianmoshi">
- 浅色模式
- </li><li class="iconfont icon-yejianmoshi">
- 深色模式
- </li><li class="iconfont icon-yuedu">
- 阅读模式
- </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
- <script src="/blog/assets/js/app.68c9df80.js" defer></script><script src="/blog/assets/js/2.395c0d18.js" defer></script><script src="/blog/assets/js/3.6748bd5c.js" defer></script><script src="/blog/assets/js/125.f09bc798.js" defer></script>
- </body>
- </html>
|