123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <!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.cf6c3304.css" as="style"><link rel="preload" href="/blog/assets/js/app.b419507c.js" as="script"><link rel="preload" href="/blog/assets/js/2.602aac03.js" as="script"><link rel="preload" href="/blog/assets/js/125.07ad81ea.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.05bc42d6.js"><link rel="prefetch" href="/blog/assets/js/100.93782085.js"><link rel="prefetch" href="/blog/assets/js/101.49f33592.js"><link rel="prefetch" href="/blog/assets/js/102.b391aaca.js"><link rel="prefetch" href="/blog/assets/js/103.b5c297df.js"><link rel="prefetch" href="/blog/assets/js/104.1b8956b0.js"><link rel="prefetch" href="/blog/assets/js/105.4af5ed2a.js"><link rel="prefetch" href="/blog/assets/js/106.f5ff0141.js"><link rel="prefetch" href="/blog/assets/js/107.9b0935ed.js"><link rel="prefetch" href="/blog/assets/js/108.a3b3e687.js"><link rel="prefetch" href="/blog/assets/js/109.0faeea62.js"><link rel="prefetch" href="/blog/assets/js/11.803b5050.js"><link rel="prefetch" href="/blog/assets/js/110.05696e77.js"><link rel="prefetch" href="/blog/assets/js/111.33bbfeaf.js"><link rel="prefetch" href="/blog/assets/js/112.cc349461.js"><link rel="prefetch" href="/blog/assets/js/113.ee6a59a5.js"><link rel="prefetch" href="/blog/assets/js/114.837d6a71.js"><link rel="prefetch" href="/blog/assets/js/115.035a54c0.js"><link rel="prefetch" href="/blog/assets/js/116.bffbfdca.js"><link rel="prefetch" href="/blog/assets/js/117.effbf98c.js"><link rel="prefetch" href="/blog/assets/js/118.a2ce28a1.js"><link rel="prefetch" href="/blog/assets/js/119.da6e315d.js"><link rel="prefetch" href="/blog/assets/js/12.68f9aa15.js"><link rel="prefetch" href="/blog/assets/js/120.edc4f23e.js"><link rel="prefetch" href="/blog/assets/js/121.67388947.js"><link rel="prefetch" href="/blog/assets/js/122.0e892f37.js"><link rel="prefetch" href="/blog/assets/js/123.9c12e399.js"><link rel="prefetch" href="/blog/assets/js/124.e265d82a.js"><link rel="prefetch" href="/blog/assets/js/126.30be0256.js"><link rel="prefetch" href="/blog/assets/js/127.daf6f659.js"><link rel="prefetch" href="/blog/assets/js/128.c3aa5522.js"><link rel="prefetch" href="/blog/assets/js/129.60c2ac70.js"><link rel="prefetch" href="/blog/assets/js/13.b2f4726e.js"><link rel="prefetch" href="/blog/assets/js/130.283b36c2.js"><link rel="prefetch" href="/blog/assets/js/131.36fd29f9.js"><link rel="prefetch" href="/blog/assets/js/132.aa486fed.js"><link rel="prefetch" href="/blog/assets/js/133.5244b658.js"><link rel="prefetch" href="/blog/assets/js/134.5d546ce7.js"><link rel="prefetch" href="/blog/assets/js/135.efe5189e.js"><link rel="prefetch" href="/blog/assets/js/136.0e15e278.js"><link rel="prefetch" href="/blog/assets/js/137.9ed0177b.js"><link rel="prefetch" href="/blog/assets/js/138.0b8bc204.js"><link rel="prefetch" href="/blog/assets/js/139.cc005358.js"><link rel="prefetch" href="/blog/assets/js/14.8dc92978.js"><link rel="prefetch" href="/blog/assets/js/140.bc32a870.js"><link rel="prefetch" href="/blog/assets/js/141.acfd1af2.js"><link rel="prefetch" href="/blog/assets/js/142.4acb4dd6.js"><link rel="prefetch" href="/blog/assets/js/143.8182807e.js"><link rel="prefetch" href="/blog/assets/js/144.20a6c974.js"><link rel="prefetch" href="/blog/assets/js/145.f3a9911c.js"><link rel="prefetch" href="/blog/assets/js/146.3ed86675.js"><link rel="prefetch" href="/blog/assets/js/147.fa9b3898.js"><link rel="prefetch" href="/blog/assets/js/148.f498d3e2.js"><link rel="prefetch" href="/blog/assets/js/149.3fe441c6.js"><link rel="prefetch" href="/blog/assets/js/15.c32eb5e6.js"><link rel="prefetch" href="/blog/assets/js/150.6d73379d.js"><link rel="prefetch" href="/blog/assets/js/151.4916058e.js"><link rel="prefetch" href="/blog/assets/js/152.42f788ce.js"><link rel="prefetch" href="/blog/assets/js/153.57ac80e4.js"><link rel="prefetch" href="/blog/assets/js/154.46b3a2b3.js"><link rel="prefetch" href="/blog/assets/js/155.f16ed794.js"><link rel="prefetch" href="/blog/assets/js/156.7004ac8c.js"><link rel="prefetch" href="/blog/assets/js/157.54029a82.js"><link rel="prefetch" href="/blog/assets/js/158.d1a36e56.js"><link rel="prefetch" href="/blog/assets/js/159.e3aba89f.js"><link rel="prefetch" href="/blog/assets/js/16.ce96f674.js"><link rel="prefetch" href="/blog/assets/js/160.da511416.js"><link rel="prefetch" href="/blog/assets/js/161.e4fc79bf.js"><link rel="prefetch" href="/blog/assets/js/162.f214074e.js"><link rel="prefetch" href="/blog/assets/js/163.4bf1ce2d.js"><link rel="prefetch" href="/blog/assets/js/164.50c2a26a.js"><link rel="prefetch" href="/blog/assets/js/165.3fadd30d.js"><link rel="prefetch" href="/blog/assets/js/166.b46fceba.js"><link rel="prefetch" href="/blog/assets/js/167.6c6747d8.js"><link rel="prefetch" href="/blog/assets/js/168.87ccce63.js"><link rel="prefetch" href="/blog/assets/js/169.e1e1c58b.js"><link rel="prefetch" href="/blog/assets/js/17.a693fe7f.js"><link rel="prefetch" href="/blog/assets/js/170.755abdff.js"><link rel="prefetch" href="/blog/assets/js/171.a6b69067.js"><link rel="prefetch" href="/blog/assets/js/172.52c10d67.js"><link rel="prefetch" href="/blog/assets/js/173.568ec26d.js"><link rel="prefetch" href="/blog/assets/js/174.f6ff5c51.js"><link rel="prefetch" href="/blog/assets/js/175.f2d646a9.js"><link rel="prefetch" href="/blog/assets/js/176.2fd93f9c.js"><link rel="prefetch" href="/blog/assets/js/177.fc5683f6.js"><link rel="prefetch" href="/blog/assets/js/178.432e7e1f.js"><link rel="prefetch" href="/blog/assets/js/179.e63b01b0.js"><link rel="prefetch" href="/blog/assets/js/18.6df3c873.js"><link rel="prefetch" href="/blog/assets/js/180.7a136172.js"><link rel="prefetch" href="/blog/assets/js/181.6e78e56b.js"><link rel="prefetch" href="/blog/assets/js/182.73d2f94a.js"><link rel="prefetch" href="/blog/assets/js/183.dce8f42f.js"><link rel="prefetch" href="/blog/assets/js/184.94ec7685.js"><link rel="prefetch" href="/blog/assets/js/185.c3561080.js"><link rel="prefetch" href="/blog/assets/js/186.63b6c4b4.js"><link rel="prefetch" href="/blog/assets/js/187.b1ca4046.js"><link rel="prefetch" href="/blog/assets/js/188.6525cd10.js"><link rel="prefetch" href="/blog/assets/js/189.fdd57a16.js"><link rel="prefetch" href="/blog/assets/js/19.6ffd68ce.js"><link rel="prefetch" href="/blog/assets/js/190.8d9ac4f5.js"><link rel="prefetch" href="/blog/assets/js/191.f19beada.js"><link rel="prefetch" href="/blog/assets/js/192.bcd02302.js"><link rel="prefetch" href="/blog/assets/js/193.05afb721.js"><link rel="prefetch" href="/blog/assets/js/194.698e74d2.js"><link rel="prefetch" href="/blog/assets/js/195.70ee23b9.js"><link rel="prefetch" href="/blog/assets/js/196.14c12f32.js"><link rel="prefetch" href="/blog/assets/js/197.52e07cb7.js"><link rel="prefetch" href="/blog/assets/js/198.6312a976.js"><link rel="prefetch" href="/blog/assets/js/199.600b8211.js"><link rel="prefetch" href="/blog/assets/js/20.d994b814.js"><link rel="prefetch" href="/blog/assets/js/200.1658389e.js"><link rel="prefetch" href="/blog/assets/js/201.f2ecc5d4.js"><link rel="prefetch" href="/blog/assets/js/202.05a5bb1c.js"><link rel="prefetch" href="/blog/assets/js/203.893b83ad.js"><link rel="prefetch" href="/blog/assets/js/204.a90c3691.js"><link rel="prefetch" href="/blog/assets/js/205.d82fb971.js"><link rel="prefetch" href="/blog/assets/js/206.00e0b021.js"><link rel="prefetch" href="/blog/assets/js/207.a5dbb279.js"><link rel="prefetch" href="/blog/assets/js/208.d15bb006.js"><link rel="prefetch" href="/blog/assets/js/209.00d63e46.js"><link rel="prefetch" href="/blog/assets/js/21.2587b99c.js"><link rel="prefetch" href="/blog/assets/js/210.b256d7b8.js"><link rel="prefetch" href="/blog/assets/js/211.be264f59.js"><link rel="prefetch" href="/blog/assets/js/212.9956352d.js"><link rel="prefetch" href="/blog/assets/js/213.6144a981.js"><link rel="prefetch" href="/blog/assets/js/214.926fcb0b.js"><link rel="prefetch" href="/blog/assets/js/215.19148b26.js"><link rel="prefetch" href="/blog/assets/js/216.f56e94aa.js"><link rel="prefetch" href="/blog/assets/js/217.c5a75265.js"><link rel="prefetch" href="/blog/assets/js/218.1d08fa09.js"><link rel="prefetch" href="/blog/assets/js/219.11d14310.js"><link rel="prefetch" href="/blog/assets/js/22.cbb873e2.js"><link rel="prefetch" href="/blog/assets/js/220.31c10a26.js"><link rel="prefetch" href="/blog/assets/js/221.b95f8a68.js"><link rel="prefetch" href="/blog/assets/js/222.79b831b9.js"><link rel="prefetch" href="/blog/assets/js/223.23d684a8.js"><link rel="prefetch" href="/blog/assets/js/224.86b7a46d.js"><link rel="prefetch" href="/blog/assets/js/225.ba05abd3.js"><link rel="prefetch" href="/blog/assets/js/226.759b748e.js"><link rel="prefetch" href="/blog/assets/js/227.c26a7240.js"><link rel="prefetch" href="/blog/assets/js/228.de29829d.js"><link rel="prefetch" href="/blog/assets/js/229.83cf7341.js"><link rel="prefetch" href="/blog/assets/js/23.3392ec01.js"><link rel="prefetch" href="/blog/assets/js/230.d239ed00.js"><link rel="prefetch" href="/blog/assets/js/231.ddfd0758.js"><link rel="prefetch" href="/blog/assets/js/232.6b57acfb.js"><link rel="prefetch" href="/blog/assets/js/233.a104a750.js"><link rel="prefetch" href="/blog/assets/js/234.3d041b0e.js"><link rel="prefetch" href="/blog/assets/js/235.9e19c5d0.js"><link rel="prefetch" href="/blog/assets/js/236.9f300061.js"><link rel="prefetch" href="/blog/assets/js/237.9fb8d4bd.js"><link rel="prefetch" href="/blog/assets/js/238.ceec05fc.js"><link rel="prefetch" href="/blog/assets/js/24.736495d8.js"><link rel="prefetch" href="/blog/assets/js/25.8f5cf322.js"><link rel="prefetch" href="/blog/assets/js/26.67d8ecd5.js"><link rel="prefetch" href="/blog/assets/js/27.05800199.js"><link rel="prefetch" href="/blog/assets/js/28.72a4cebd.js"><link rel="prefetch" href="/blog/assets/js/29.f8d2f7c1.js"><link rel="prefetch" href="/blog/assets/js/3.aec45124.js"><link rel="prefetch" href="/blog/assets/js/30.0ac25def.js"><link rel="prefetch" href="/blog/assets/js/31.4d385616.js"><link rel="prefetch" href="/blog/assets/js/32.ab6922e1.js"><link rel="prefetch" href="/blog/assets/js/33.22aedb73.js"><link rel="prefetch" href="/blog/assets/js/34.1176b400.js"><link rel="prefetch" href="/blog/assets/js/35.d4d05428.js"><link rel="prefetch" href="/blog/assets/js/36.6dd0dde1.js"><link rel="prefetch" href="/blog/assets/js/37.4af0c50a.js"><link rel="prefetch" href="/blog/assets/js/38.1a98317a.js"><link rel="prefetch" href="/blog/assets/js/39.8383d231.js"><link rel="prefetch" href="/blog/assets/js/4.6a499ed7.js"><link rel="prefetch" href="/blog/assets/js/40.ea1ea46b.js"><link rel="prefetch" href="/blog/assets/js/41.29846640.js"><link rel="prefetch" href="/blog/assets/js/42.9c906181.js"><link rel="prefetch" href="/blog/assets/js/43.344bd56a.js"><link rel="prefetch" href="/blog/assets/js/44.e23af589.js"><link rel="prefetch" href="/blog/assets/js/45.fa09e088.js"><link rel="prefetch" href="/blog/assets/js/46.ddf18f6d.js"><link rel="prefetch" href="/blog/assets/js/47.593a3a96.js"><link rel="prefetch" href="/blog/assets/js/48.fb21c024.js"><link rel="prefetch" href="/blog/assets/js/49.5bb86e0c.js"><link rel="prefetch" href="/blog/assets/js/5.48f0d794.js"><link rel="prefetch" href="/blog/assets/js/50.0fb55bed.js"><link rel="prefetch" href="/blog/assets/js/51.a38b4abd.js"><link rel="prefetch" href="/blog/assets/js/52.70f6922c.js"><link rel="prefetch" href="/blog/assets/js/53.c7e04159.js"><link rel="prefetch" href="/blog/assets/js/54.ff09ad12.js"><link rel="prefetch" href="/blog/assets/js/55.57d17d47.js"><link rel="prefetch" href="/blog/assets/js/56.a58b3cc3.js"><link rel="prefetch" href="/blog/assets/js/57.9de5f95b.js"><link rel="prefetch" href="/blog/assets/js/58.d15857bf.js"><link rel="prefetch" href="/blog/assets/js/59.ff3f0900.js"><link rel="prefetch" href="/blog/assets/js/6.1505523f.js"><link rel="prefetch" href="/blog/assets/js/60.bc9edb0a.js"><link rel="prefetch" href="/blog/assets/js/61.ec369f58.js"><link rel="prefetch" href="/blog/assets/js/62.75c1dd19.js"><link rel="prefetch" href="/blog/assets/js/63.a932b576.js"><link rel="prefetch" href="/blog/assets/js/64.d821c8d4.js"><link rel="prefetch" href="/blog/assets/js/65.c48ce70a.js"><link rel="prefetch" href="/blog/assets/js/66.6fc46ec0.js"><link rel="prefetch" href="/blog/assets/js/67.5a70400c.js"><link rel="prefetch" href="/blog/assets/js/68.6a172c1e.js"><link rel="prefetch" href="/blog/assets/js/69.d878fdd4.js"><link rel="prefetch" href="/blog/assets/js/7.b38bde58.js"><link rel="prefetch" href="/blog/assets/js/70.61fcea39.js"><link rel="prefetch" href="/blog/assets/js/71.b4f867d8.js"><link rel="prefetch" href="/blog/assets/js/72.d6eafa00.js"><link rel="prefetch" href="/blog/assets/js/73.7937e89b.js"><link rel="prefetch" href="/blog/assets/js/74.3ff087d7.js"><link rel="prefetch" href="/blog/assets/js/75.97ca5f60.js"><link rel="prefetch" href="/blog/assets/js/76.ece1fc97.js"><link rel="prefetch" href="/blog/assets/js/77.95cdf309.js"><link rel="prefetch" href="/blog/assets/js/78.da225d8a.js"><link rel="prefetch" href="/blog/assets/js/79.ae629400.js"><link rel="prefetch" href="/blog/assets/js/8.f710ef8c.js"><link rel="prefetch" href="/blog/assets/js/80.cf6d2811.js"><link rel="prefetch" href="/blog/assets/js/81.6c5fdca6.js"><link rel="prefetch" href="/blog/assets/js/82.245ed394.js"><link rel="prefetch" href="/blog/assets/js/83.4b549b0f.js"><link rel="prefetch" href="/blog/assets/js/84.17cebe69.js"><link rel="prefetch" href="/blog/assets/js/85.b1179a10.js"><link rel="prefetch" href="/blog/assets/js/86.ad526400.js"><link rel="prefetch" href="/blog/assets/js/87.2eef9fa1.js"><link rel="prefetch" href="/blog/assets/js/88.92f778ed.js"><link rel="prefetch" href="/blog/assets/js/89.efe59f09.js"><link rel="prefetch" href="/blog/assets/js/9.bf9d8b8d.js"><link rel="prefetch" href="/blog/assets/js/90.26e610ca.js"><link rel="prefetch" href="/blog/assets/js/91.f78cb514.js"><link rel="prefetch" href="/blog/assets/js/92.d7983929.js"><link rel="prefetch" href="/blog/assets/js/93.20272a60.js"><link rel="prefetch" href="/blog/assets/js/94.245150bc.js"><link rel="prefetch" href="/blog/assets/js/95.6f0e48c2.js"><link rel="prefetch" href="/blog/assets/js/96.02cf7f8b.js"><link rel="prefetch" href="/blog/assets/js/97.a9438771.js"><link rel="prefetch" href="/blog/assets/js/98.12762ccb.js"><link rel="prefetch" href="/blog/assets/js/99.ddbea38c.js">
- <link rel="stylesheet" href="/blog/assets/css/0.styles.cf6c3304.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/" class="sidebar-link">Git基础与命令</a></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/" aria-current="page" class="active sidebar-link">Git工具-重写历史</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/blog/pages/1832fe/#修改最后一次提交" class="sidebar-link">修改最后一次提交</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/blog/pages/1832fe/#修改提交信息" class="sidebar-link">修改提交信息</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/1832fe/#修改实际内容" class="sidebar-link">修改实际内容</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/blog/pages/1832fe/#修改多个提交信息" class="sidebar-link">修改多个提交信息</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/1832fe/#重新排序提交" class="sidebar-link">重新排序提交</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/1832fe/#压缩提交" class="sidebar-link">压缩提交</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/1832fe/#拆分提交" class="sidebar-link">拆分提交</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/1832fe/#核武器级选项-filter-branch" class="sidebar-link">核武器级选项:filter-branch</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/blog/pages/1832fe/#从每一个提交中移除一个文件" class="sidebar-link">从每一个提交中移除一个文件</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/1832fe/#使一个子目录做为新的根目录" class="sidebar-link">使一个子目录做为新的根目录</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/1832fe/#全局修改邮箱地址" class="sidebar-link">全局修改邮箱地址</a></li></ul></li></ul></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-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/blog/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/blog/note/git/#《Git》学习笔记" data-v-06225672>《Git》学习笔记</a></li><li data-v-06225672><a href="/blog/note/git/#文档笔记" data-v-06225672>文档笔记</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/heBody" target="_blank" title="作者" class="beLink" data-v-06225672>heBody</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>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>许多时候,在使用 Git 时,你可能想要修订提交历史。 Git 很棒的一点是它允许你在最后时刻做决定。 你可以在将暂存区内容提交前决定哪些文件进入提交,可以通过 <code>git stash</code> 来决定不与某些内容工作, 也可以重写已经发生的提交就像它们以另一种方式发生的一样。 这可能涉及改变提交的顺序,改变提交中的信息或修改文件,将提交压缩或是拆分, 或完全地移除提交——在将你的工作成果与他人共享之前。</p> <p>在本节中,你可以学到如何完成这些工作,这样在与他人分享你的工作成果时你的提交历史将如你所愿地展示出来。</p> <table><thead><tr><th>Note</th> <th>在满意之前不要推送你的工作Git 的基本原则之一是,由于克隆中有很多工作是本地的,因此你可以 <strong>在本地</strong> 随便重写历史记录。 然而一旦推送了你的工作,那就完全是另一回事了,除非你有充分的理由进行更改,否则应该将推送的工作视为最终结果。 简而言之,在对它感到满意并准备与他人分享之前,应当避免推送你的工作。</th></tr></thead> <tbody><tr><td></td> <td></td></tr></tbody></table> <h2 id="修改最后一次提交"><a href="#修改最后一次提交" class="header-anchor">#</a> 修改最后一次提交</h2> <p>修改你最近一次提交可能是所有修改历史提交的操作中最常见的一个。 对于你的最近一次提交,你往往想做两件事情:简单地修改提交信息, 或者通过添加、移除或修改文件来更改提交实际的内容。</p> <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> commit <span class="token parameter variable">--amend</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>上面这条命令会将最后一次的提交信息载入到编辑器中供你修改。 当保存并关闭编辑器后,编辑器会将更新后的提交信息写入新提交中,它会成为新的最后一次提交。</p> <h3 id="修改实际内容"><a href="#修改实际内容" class="header-anchor">#</a> 修改实际内容</h3> <p>另一方面,如果你想要修改最后一次提交的实际内容,那么流程很相似:首先作出你想要补上的修改, 暂存它们,然后用 <code>git commit --amend</code> 以新的改进后的提交来 <strong>替换</strong> 掉旧有的最后一次提交,</p> <p>使用这个技巧的时候需要小心,因为修正会改变提交的 SHA-1 校验和。 它类似于一个小的变基——<strong>如果已经推送了最后一次提交就不要修正它</strong>。</p> <table><thead><tr><th>Tip</th> <th>修补后的提交可能需要修补提交信息当你在修补一次提交时,可以同时修改提交信息和提交内容。 如果你修补了提交的内容,那么几乎肯定要更新提交消息以反映修改后的内容。另一方面,如果你的修补是琐碎的(如修改了一个笔误或添加了一个忘记暂存的文件), 那么之前的提交信息不必修改,你只需作出更改,暂存它们,然后通过以下命令避免不必要的编辑器环节即可:<code>$ git commit --amend --no-edit</code></th></tr></thead> <tbody><tr><td></td> <td></td></tr></tbody></table> <h2 id="修改多个提交信息"><a href="#修改多个提交信息" class="header-anchor">#</a> 修改多个提交信息</h2> <p>为了修改在提交历史中较远的提交,必须使用更复杂的工具。 Git 没有一个改变历史工具,但是可以使用变基工具来变基一系列提交,基于它们原来的 HEAD 而不是将其移动到另一个新的上面。 通过交互式变基工具,可以在任何想要修改的提交后停止,然后修改信息、添加文件或做任何想做的事情。 可以通过给 <code>git rebase</code> 增加 <code>-i</code> 选项来交互式地运行变基。 必须指定想要重写多久远的历史,这可以通过告诉命令将要变基到的提交来做到。</p> <p>例如,如果想要修改最近三次提交信息,或者那组提交中的任意一个提交信息, 将想要修改的最近一次提交的父提交作为参数传递给 <code>git rebase -i</code> 命令,即 <code>HEAD~2^</code> 或 <code>HEAD~3</code>。 记住 <code>~3</code> 可能比较容易,因为你正尝试修改最后三次提交;但是注意实际上指定了以前的四次提交,即想要修改提交的父提交:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> rebase <span class="token parameter variable">-i</span> HEAD~3
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>再次记住这是一个变基命令——在 <code>HEAD~3..HEAD</code> 范围内的每一个修改了提交信息的提交及其 <strong>所有后裔</strong> 都会被重写。 不要涉及任何已经推送到中央服务器的提交——这样做会产生一次变更的两个版本,因而使他人困惑。</p> <p>运行这个命令会在文本编辑器上给你一个提交的列表,看起来像下面这样:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>pick f7f3f6d changed my name a bit
- pick 310154e updated README formatting and added blame
- pick a5f4a0d added cat-file
- <span class="token comment"># Rebase 710f0f8..a5f4a0d onto 710f0f8</span>
- <span class="token comment">#</span>
- <span class="token comment"># Commands:</span>
- <span class="token comment"># p, pick <commit> = use commit</span>
- <span class="token comment"># r, reword <commit> = use commit, but edit the commit message</span>
- <span class="token comment"># e, edit <commit> = use commit, but stop for amending</span>
- <span class="token comment"># s, squash <commit> = use commit, but meld into previous commit</span>
- <span class="token comment"># f, fixup <commit> = like "squash", but discard this commit's log message</span>
- <span class="token comment"># x, exec <command> = run command (the rest of the line) using shell</span>
- <span class="token comment"># b, break = stop here (continue rebase later with 'git rebase --continue')</span>
- <span class="token comment"># d, drop <commit> = remove commit</span>
- <span class="token comment"># l, label <label> = label current HEAD with a name</span>
- <span class="token comment"># t, reset <label> = reset HEAD to a label</span>
- <span class="token comment"># m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]</span>
- <span class="token comment"># . create a merge commit using the original merge commit's</span>
- <span class="token comment"># . message (or the oneline, if no original merge commit was</span>
- <span class="token comment"># . specified). Use -c <commit> to reword the commit message.</span>
- <span class="token comment">#</span>
- <span class="token comment"># These lines can be re-ordered; they are executed from top to bottom.</span>
- <span class="token comment">#</span>
- <span class="token comment"># If you remove a line here THAT COMMIT WILL BE LOST.</span>
- <span class="token comment">#</span>
- <span class="token comment"># However, if you remove everything, the rebase will be aborted.</span>
- <span class="token comment">#</span>
- <span class="token comment"># Note that empty commits are commented out</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><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><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br></div></div><p>需要重点注意的是相对于正常使用的 <code>log</code> 命令,这些提交显示的顺序是相反的。 运行一次 <em>log</em> 命令,会看到类似这样的东西:</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> HEAD~3<span class="token punctuation">..</span>HEAD
- a5f4a0d added cat-file
- 310154e updated README formatting and added blame
- f7f3f6d changed my name a bit
- </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>HEAD~3</code>)开始,从上到下的依次重演每一个提交引入的修改。 它将最旧的而不是最新的列在上面,因为那会是第一个将要重演的。</p> <p>你需要修改脚本来让它停留在你想修改的变更上。 要达到这个目的,你只要将你想修改的每一次提交前面的 ‘pick’ 改为 ‘edit’。 例如,只想修改第三次提交信息,可以像下面这样修改文件:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>edit f7f3f6d changed my name a bit
- pick 310154e updated README formatting and added blame
- pick a5f4a0d added cat-file
- </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>当保存并退出编辑器时,Git 将你带回到列表中的最后一次提交,把你送回命令行并提示以下信息:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> rebase <span class="token parameter variable">-i</span> HEAD~3
- Stopped at f7f3f6d<span class="token punctuation">..</span>. changed my name a bit
- You can amend the commit now, with
- <span class="token function">git</span> commit <span class="token parameter variable">--amend</span>
- Once you're satisfied with your changes, run
- <span class="token function">git</span> rebase <span class="token parameter variable">--continue</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><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">--amend</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> rebase <span class="token parameter variable">--continue</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这个命令将会自动地应用另外两个提交,然后就完成了。 如果需要将不止一处的 pick 改为 edit,需要在每一个修改为 edit 的提交上重复这些步骤。 每一次,Git 将会停止,让你修正提交,然后继续直到完成。</p> <h2 id="重新排序提交"><a href="#重新排序提交" class="header-anchor">#</a> 重新排序提交</h2> <p>也可以使用交互式变基来重新排序或完全移除提交。 如果想要移除 “added cat-file” 提交然后修改另外两个提交引入的顺序,可以将变基脚本从这样:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>pick f7f3f6d changed my name a bit
- pick 310154e updated README formatting and added blame
- pick a5f4a0d added cat-file
- </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> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>pick 310154e updated README formatting and added blame
- pick f7f3f6d changed my name a bit
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>当保存并退出编辑器时,Git 将你的分支带回这些提交的父提交,应用 <code>310154e</code> 然后应用 <code>f7f3f6d</code>,最后停止。 事实修改了那些提交的顺序并完全地移除了 “added cat-file” 提交。</p> <h2 id="压缩提交"><a href="#压缩提交" class="header-anchor">#</a> 压缩提交</h2> <p>通过交互式变基工具,也可以将一连串提交压缩成一个单独的提交。 在变基信息中脚本给出了有用的指令:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment">#</span>
- <span class="token comment"># Commands:</span>
- <span class="token comment"># p, pick <commit> = use commit</span>
- <span class="token comment"># r, reword <commit> = use commit, but edit the commit message</span>
- <span class="token comment"># e, edit <commit> = use commit, but stop for amending</span>
- <span class="token comment"># s, squash <commit> = use commit, but meld into previous commit</span>
- <span class="token comment"># f, fixup <commit> = like "squash", but discard this commit's log message</span>
- <span class="token comment"># x, exec <command> = run command (the rest of the line) using shell</span>
- <span class="token comment"># b, break = stop here (continue rebase later with 'git rebase --continue')</span>
- <span class="token comment"># d, drop <commit> = remove commit</span>
- <span class="token comment"># l, label <label> = label current HEAD with a name</span>
- <span class="token comment"># t, reset <label> = reset HEAD to a label</span>
- <span class="token comment"># m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]</span>
- <span class="token comment"># . create a merge commit using the original merge commit's</span>
- <span class="token comment"># . message (or the oneline, if no original merge commit was</span>
- <span class="token comment"># . specified). Use -c <commit> to reword the commit message.</span>
- <span class="token comment">#</span>
- <span class="token comment"># These lines can be re-ordered; they are executed from top to bottom.</span>
- <span class="token comment">#</span>
- <span class="token comment"># If you remove a line here THAT COMMIT WILL BE LOST.</span>
- <span class="token comment">#</span>
- <span class="token comment"># However, if you remove everything, the rebase will be aborted.</span>
- <span class="token comment">#</span>
- <span class="token comment"># Note that empty commits are commented out</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><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><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><p>如果,指定 “squash” 而不是 “pick” 或 “edit”,Git 将应用两者的修改并合并提交信息在一起。 所以,如果想要这三次提交变为一个提交,可以这样修改脚本:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>pick f7f3f6d changed my name a bit
- squash 310154e updated README formatting and added blame
- squash a5f4a0d added cat-file
- </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>当保存并退出编辑器时,Git 应用所有的三次修改然后将你放到编辑器中来合并三次提交信息:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># This is a combination of 3 commits.</span>
- <span class="token comment"># The first commit's message is:</span>
- changed my name a bit
- <span class="token comment"># This is the 2nd commit message:</span>
- updated README formatting and added blame
- <span class="token comment"># This is the 3rd commit message:</span>
- added cat-file
- </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><p>当你保存之后,你就拥有了一个包含前三次提交的全部变更的提交。</p> <h2 id="拆分提交"><a href="#拆分提交" class="header-anchor">#</a> 拆分提交</h2> <p>拆分一个提交会撤消这个提交,然后多次地部分地暂存与提交直到完成你所需次数的提交。 例如,假设想要拆分三次提交的中间那次提交。 想要将它拆分为两次提交:第一个 “updated README formatting”,第二个 “added blame” 来代替原来的 “updated README formatting and added blame”。 可以通过修改 <code>rebase -i</code> 的脚本来做到这点,将要拆分的提交的指令修改为 “edit”:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>pick f7f3f6d changed my name a bit
- edit 310154e updated README formatting and added blame
- pick a5f4a0d added cat-file
- </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>然后,当脚本带你进入到命令行时,重置那个提交,拿到被重置的修改,从中创建几次提交。 当保存并退出编辑器时,Git 带你到列表中第一个提交的父提交,应用第一个提交(<code>f7f3f6d</code>), 应用第二个提交(<code>310154e</code>),然后让你进入命令行。 那里,可以通过 <code>git reset HEAD^</code> 做一次针对那个提交的混合重置,实际上将会撤消那次提交并将修改的文件取消暂存。 现在可以暂存并提交文件直到有几个提交,然后当完成时运行 <code>git rebase --continue</code>:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> reset HEAD^
- $ <span class="token function">git</span> <span class="token function">add</span> README
- $ <span class="token function">git</span> commit <span class="token parameter variable">-m</span> <span class="token string">'updated README formatting'</span>
- $ <span class="token function">git</span> <span class="token function">add</span> lib/simplegit.rb
- $ <span class="token function">git</span> commit <span class="token parameter variable">-m</span> <span class="token string">'added blame'</span>
- $ <span class="token function">git</span> rebase <span class="token parameter variable">--continue</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></div></div><p>Git 在脚本中应用最后一次提交(<code>a5f4a0d</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">-4</span> <span class="token parameter variable">--pretty</span><span class="token operator">=</span>format:<span class="token string">"%h %s"</span>
- 1c002dd added cat-file
- 9b29157 added blame
- 35cfb2b updated README formatting
- f3cc40e changed my name a bit
- </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>再次强调,这些改动了所有在列表中的提交的 SHA-1 校验和,所以要确保列表中的提交还没有推送到共享仓库中。</p> <h2 id="核武器级选项-filter-branch"><a href="#核武器级选项-filter-branch" class="header-anchor">#</a> 核武器级选项:filter-branch</h2> <p>有另一个历史改写的选项,如果想要通过脚本的方式改写大量提交的话可以使用它——例如,全局修改你的邮箱地址或从每一个提交中移除一个文件。 这个命令是 <code>filter-branch</code>,它可以改写历史中大量的提交,除非你的项目还没有公开并且其他人没有基于要改写的工作的提交做的工作,否则你不应当使用它。 然而,它可以很有用。 你将会学习到几个常用的用途,这样就得到了它适合使用地方的想法。</p> <table><thead><tr><th>Caution</th> <th><code>git filter-branch</code> 有很多陷阱,不再推荐使用它来重写历史。 请考虑使用 <code>git-filter-repo</code>,它是一个 Python 脚本,相比大多数使用 <code>filter-branch</code> 的应用来说,它做得要更好。它的文档和源码可访问 https://github.com/newren/git-filter-repo 获取。</th></tr></thead> <tbody><tr><td></td> <td></td></tr></tbody></table> <h3 id="从每一个提交中移除一个文件"><a href="#从每一个提交中移除一个文件" class="header-anchor">#</a> 从每一个提交中移除一个文件</h3> <p>这经常发生。 有人粗心地通过 <code>git add .</code> 提交了一个巨大的二进制文件,你想要从所有地方删除。 可能偶然地提交了一个包括一个密码的文件,然而你想要开源项目。 <code>filter-branch</code> 是一个可能会用来擦洗整个提交历史的工具。 为了从整个提交历史中移除一个叫做 <code>passwords.txt</code> 的文件,可以使用 <code>--tree-filter</code> 选项给 <code>filter-branch</code>:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> filter-branch --tree-filter <span class="token string">'rm -f passwords.txt'</span> HEAD
- Rewrite 6b9b3cf04e7c5686a9cb838c3f36a8cb6a0fc2bd <span class="token punctuation">(</span><span class="token number">21</span>/21<span class="token punctuation">)</span>
- Ref <span class="token string">'refs/heads/master'</span> was rewritten
- </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>--tree-filter</code> 选项在检出项目的每一个提交后运行指定的命令然后重新提交结果。 在本例中,你从每一个快照中移除了一个叫作 <code>passwords.txt</code> 的文件,无论它是否存在。 如果想要移除所有偶然提交的编辑器备份文件,可以运行类似 <code>git filter-branch --tree-filter 'rm -f *~' HEAD</code> 的命令。</p> <p>最后将可以看到 Git 重写树与提交然后移动分支指针。 通常一个好的想法是在一个测试分支中做这件事,然后当你决定最终结果是真正想要的,可以硬重置 <code>master</code> 分支。 为了让 <code>filter-branch</code> 在所有分支上运行,可以给命令传递 <code>--all</code> 选项。</p> <h3 id="使一个子目录做为新的根目录"><a href="#使一个子目录做为新的根目录" class="header-anchor">#</a> 使一个子目录做为新的根目录</h3> <p>假设已经从另一个源代码控制系统中导入,并且有几个没意义的子目录(<code>trunk</code>、<code>tags</code> 等等)。 如果想要让 <code>trunk</code> 子目录作为每一个提交的新的项目根目录,<code>filter-branch</code> 也可以帮助你那么做:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> filter-branch --subdirectory-filter trunk HEAD
- Rewrite 856f0bf61e41a27326cdae8f09fe708d679f596f <span class="token punctuation">(</span><span class="token number">12</span>/12<span class="token punctuation">)</span>
- Ref <span class="token string">'refs/heads/master'</span> was rewritten
- </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>trunk</code> 子目录了。 Git 会自动移除所有不影响子目录的提交。</p> <h3 id="全局修改邮箱地址"><a href="#全局修改邮箱地址" class="header-anchor">#</a> 全局修改邮箱地址</h3> <p>另一个常见的情形是在你开始工作时忘记运行 <code>git config</code> 来设置你的名字与邮箱地址, 或者你想要开源一个项目并且修改所有你的工作邮箱地址为你的个人邮箱地址。 任何情形下,你也可以通过 <code>filter-branch</code> 来一次性修改多个提交中的邮箱地址。 需要小心的是只修改你自己的邮箱地址,所以你使用 <code>--commit-filter</code>:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> filter-branch --commit-filter <span class="token string">'
- if [ "$GIT_AUTHOR_EMAIL" = "schacon@localhost" ];
- then
- GIT_AUTHOR_NAME="Scott Chacon";
- GIT_AUTHOR_EMAIL="schacon@example.com";
- git commit-tree "$@";
- else
- git commit-tree "$@";
- fi'</span> HEAD
- </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><p>这会遍历并重写每一个提交来包含你的新邮箱地址。 因为提交包含了它们父提交的 SHA-1 校验和,这个命令会修改你的历史中的每一个提交的 SHA-1 校验和, 而不仅仅只是那些匹配邮箱地址的提交。</p></div></div> <div class="page-edit"><div class="edit-link"><a href="https://github.com/heBody/blog/edit/master/docs/《Git》学习笔记/20.文档笔记/100.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/76d859/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">Git工具-交互式暂存</div></a> <a href="/blog/pages/d9e9c6/" 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/76d859/" class="prev">Git工具-交互式暂存</a></span> <span class="next"><a href="/blog/pages/d9e9c6/">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><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div>
- Theme by
- <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a>
- | Copyright © 2019-2022
- <span>Evan Xu | <a href="https://github.com/heBody/blob/master/LICENSE" 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.b419507c.js" defer></script><script src="/blog/assets/js/2.602aac03.js" defer></script><script src="/blog/assets/js/125.07ad81ea.js" defer></script>
- </body>
- </html>
|