Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FredZeng committed Feb 20, 2024
1 parent dd98854 commit 12c04bb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 2021/11/19/git/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="zh-cn"><head><meta name="generator" content="Hexo 3.9.0"><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="theme-color" content="#f8f5ec"><meta name="msapplication-navbutton-color" content="#f8f5ec"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec"><meta name="description" content="Git 速记"><meta property="og:title" content="Git 速记"><meta property="og:description" content="Git 速记"><meta name="keywords" content="FredZeng,FredTsang,Blog,TF5,TECH F5VE"><link rel="alternate" href="/atom.xml" title="FredTsang"><link rel="canonical" href="https://fredzeng.github.io/2021/11/19/git/"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/css/style.css?v="><script id="baidu_push">!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script>window.config={leancloud:"",toc:!0,fancybox:"",pjax:"",latex:""}</script><title>Git 速记 - FredTsang</title></head><body><div id="mobile-navbar" class="mobile-navbar"><div class="mobile-header-logo"> <a href="/." class="logo">FredTsang</a></div><div class="mobile-navbar-icon"><span></span><span></span><span></span></div></div><nav id="mobile-menu" class="mobile-menu slideout-menu"><ul class="mobile-menu-list"><a href="/"><li class="mobile-menu-item">Home</li></a><a href="/archives/"><li class="mobile-menu-item">Archives</li></a><a href="/categories/"><li class="mobile-menu-item">Categories</li></a></ul></nav><div class="container" id="mobile-panel"><header id="header" class="header"><div class="logo-wrapper"> <a href="/." class="logo">FredTsang</a></div><nav class="site-navbar"><ul id="menu" class="menu"><li class="menu-item"> <a class="menu-item-link" href="/">Home</a></li><li class="menu-item"> <a class="menu-item-link" href="/archives/">Archives</a></li><li class="menu-item"> <a class="menu-item-link" href="/categories/">Categories</a></li></ul></nav></header><main id="main" class="main"><div class="content-wrapper"><div id="content" class="content"><article class="post"><header class="post-header"><h1 class="post-title">Git 速记</h1><div class="post-meta"> <span class="post-time">2021-11-19</span></div></header><div class="post-content"><ul><li>添加/修改远程仓库地址</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 添加仓库地址</span></span><br><span class="line">git remote add [shortname] [url]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 修改仓库地址</span></span><br><span class="line">git remote <span class="built_in">set</span>-url [shortname] [url]</span><br></pre></td></tr></table></figure><ul><li>修改最近一次 commit 的 message</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git commit --amend</span><br></pre></td></tr></table></figure><ul><li>修改最近一次 commit 的作者信息</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git commit --amend --author <span class="string">"xxx &lt;[email protected]&gt;"</span></span><br></pre></td></tr></table></figure><ul><li>批量重置 commit author</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line"></span><br><span class="line">git filter-branch --env-filter <span class="string">'</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">OLD_EMAIL="[email protected]"</span></span><br><span class="line"><span class="string">CORRECT_NAME="Your Correct Name"</span></span><br><span class="line"><span class="string">CORRECT_EMAIL="[email protected]"</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]</span></span><br><span class="line"><span class="string">then</span></span><br><span class="line"><span class="string"> export GIT_COMMITTER_NAME="$CORRECT_NAME"</span></span><br><span class="line"><span class="string"> export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"</span></span><br><span class="line"><span class="string">fi</span></span><br><span class="line"><span class="string">if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]</span></span><br><span class="line"><span class="string">then</span></span><br><span class="line"><span class="string"> export GIT_AUTHOR_NAME="$CORRECT_NAME"</span></span><br><span class="line"><span class="string"> export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"</span></span><br><span class="line"><span class="string">fi</span></span><br><span class="line"><span class="string">'</span> --tag-name-filter cat -- --branches --tags</span><br></pre></td></tr></table></figure><ul><li>创建一个全新的分支,没有历史记录</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout --orphan &lt;branch&gt;</span><br></pre></td></tr></table></figure><ul><li>全局配置 GitHub token</li></ul><p>GitHub 不再支持 “用户名 + 密码” 的登录方式,推荐使用 GitHub token 来进行鉴权;<br>给每个 clone 下来的项目单独配置 token 过于繁琐,可以使用以下方式全局配置 GitHub token。</p><p>方法一:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global github.token &lt;你的 GitHub token&gt;</span><br><span class="line">git config --global github.user &lt;github上的用户名&gt;</span><br></pre></td></tr></table></figure><p>方法二:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global url.<span class="string">"https://&lt;你的 GitHub token&gt;@github.com"</span>.insteadOf <span class="string">"https://github.com"</span></span><br></pre></td></tr></table></figure></div><footer class="post-footer"><nav class="post-nav"><a class="prev" href="/2021/11/22/html/"><i class="iconfont icon-left"></i> <span class="prev-text nav-default">Html 速记</span> <span class="prev-text nav-mobile">Prev</span></a> <a class="next" href="/2021/11/19/media/media-fragments/"><span class="next-text nav-default">Media Fragments</span> <span class="prev-text nav-mobile">Next</span><i class="iconfont icon-right"></i></a></nav></footer></article></div><div class="comments" id="comments"></div></div></main><footer id="footer" class="footer"><div class="social-links"><a href="https://github.com/FredZeng" class="iconfont icon-github" title="github"></a></div><div class="copyright"> <span class="power-by">Powered by <a class="hexo-link" href="https://hexo.io/">Hexo</a></span> <span class="division">|</span> <span class="theme-info">Theme - <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even">Even</a></span> <span class="copyright-year">&copy;2019 - 2024<span class="heart"><i class="iconfont icon-heart"></i></span> <span class="author">FredTsang</span></span></div></footer><div class="back-to-top" id="back-to-top"><i class="iconfont icon-up"></i></div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/lib/jquery/jquery.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/lib/slideout/slideout.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/js/src/clipboard.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/js/src/clipboard-use.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/js/src/even.js?v="></script></body></html>
<!DOCTYPE html><html lang="zh-cn"><head><meta name="generator" content="Hexo 3.9.0"><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="theme-color" content="#f8f5ec"><meta name="msapplication-navbutton-color" content="#f8f5ec"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec"><meta name="description" content="Git 速记"><meta property="og:title" content="Git 速记"><meta property="og:description" content="Git 速记"><meta name="keywords" content="FredZeng,FredTsang,Blog,TF5,TECH F5VE"><link rel="alternate" href="/atom.xml" title="FredTsang"><link rel="canonical" href="https://fredzeng.github.io/2021/11/19/git/"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/css/style.css?v="><script id="baidu_push">!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script>window.config={leancloud:"",toc:!0,fancybox:"",pjax:"",latex:""}</script><title>Git 速记 - FredTsang</title></head><body><div id="mobile-navbar" class="mobile-navbar"><div class="mobile-header-logo"> <a href="/." class="logo">FredTsang</a></div><div class="mobile-navbar-icon"><span></span><span></span><span></span></div></div><nav id="mobile-menu" class="mobile-menu slideout-menu"><ul class="mobile-menu-list"><a href="/"><li class="mobile-menu-item">Home</li></a><a href="/archives/"><li class="mobile-menu-item">Archives</li></a><a href="/categories/"><li class="mobile-menu-item">Categories</li></a></ul></nav><div class="container" id="mobile-panel"><header id="header" class="header"><div class="logo-wrapper"> <a href="/." class="logo">FredTsang</a></div><nav class="site-navbar"><ul id="menu" class="menu"><li class="menu-item"> <a class="menu-item-link" href="/">Home</a></li><li class="menu-item"> <a class="menu-item-link" href="/archives/">Archives</a></li><li class="menu-item"> <a class="menu-item-link" href="/categories/">Categories</a></li></ul></nav></header><main id="main" class="main"><div class="content-wrapper"><div id="content" class="content"><article class="post"><header class="post-header"><h1 class="post-title">Git 速记</h1><div class="post-meta"> <span class="post-time">2021-11-19</span></div></header><div class="post-content"><ul><li>添加/修改远程仓库地址</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 添加仓库地址</span></span><br><span class="line">git remote add [shortname] [url]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 修改仓库地址</span></span><br><span class="line">git remote <span class="built_in">set</span>-url [shortname] [url]</span><br></pre></td></tr></table></figure><ul><li>修改最近一次 commit 的 message</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git commit --amend</span><br></pre></td></tr></table></figure><ul><li>修改最近一次 commit 的作者信息</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git commit --amend --author <span class="string">"xxx &lt;[email protected]&gt;"</span></span><br></pre></td></tr></table></figure><ul><li>批量重置 commit author</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line"></span><br><span class="line">git filter-branch --env-filter <span class="string">'</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">OLD_EMAIL="[email protected]"</span></span><br><span class="line"><span class="string">CORRECT_NAME="Your Correct Name"</span></span><br><span class="line"><span class="string">CORRECT_EMAIL="[email protected]"</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]</span></span><br><span class="line"><span class="string">then</span></span><br><span class="line"><span class="string"> export GIT_COMMITTER_NAME="$CORRECT_NAME"</span></span><br><span class="line"><span class="string"> export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"</span></span><br><span class="line"><span class="string">fi</span></span><br><span class="line"><span class="string">if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]</span></span><br><span class="line"><span class="string">then</span></span><br><span class="line"><span class="string"> export GIT_AUTHOR_NAME="$CORRECT_NAME"</span></span><br><span class="line"><span class="string"> export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"</span></span><br><span class="line"><span class="string">fi</span></span><br><span class="line"><span class="string">'</span> --tag-name-filter cat -- --branches --tags</span><br></pre></td></tr></table></figure><ul><li>创建一个全新的分支,没有历史记录</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout --orphan &lt;branch&gt;</span><br></pre></td></tr></table></figure><ul><li>加速 clone 项目</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> --depth 1 &lt;url&gt;</span><br></pre></td></tr></table></figure><ul><li>全局配置 GitHub token</li></ul><p>GitHub 不再支持 “用户名 + 密码” 的登录方式,推荐使用 GitHub token 来进行鉴权;<br>给每个 clone 下来的项目单独配置 token 过于繁琐,可以使用以下方式全局配置 GitHub token。</p><p>方法一:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global github.token &lt;你的 GitHub token&gt;</span><br><span class="line">git config --global github.user &lt;github上的用户名&gt;</span><br></pre></td></tr></table></figure><p>方法二:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global url.<span class="string">"https://&lt;你的 GitHub token&gt;@github.com"</span>.insteadOf <span class="string">"https://github.com"</span></span><br></pre></td></tr></table></figure></div><footer class="post-footer"><nav class="post-nav"><a class="prev" href="/2021/11/22/html/"><i class="iconfont icon-left"></i> <span class="prev-text nav-default">Html 速记</span> <span class="prev-text nav-mobile">Prev</span></a> <a class="next" href="/2021/11/19/media/media-fragments/"><span class="next-text nav-default">Media Fragments</span> <span class="prev-text nav-mobile">Next</span><i class="iconfont icon-right"></i></a></nav></footer></article></div><div class="comments" id="comments"></div></div></main><footer id="footer" class="footer"><div class="social-links"><a href="https://github.com/FredZeng" class="iconfont icon-github" title="github"></a></div><div class="copyright"> <span class="power-by">Powered by <a class="hexo-link" href="https://hexo.io/">Hexo</a></span> <span class="division">|</span> <span class="theme-info">Theme - <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even">Even</a></span> <span class="copyright-year">&copy;2019 - 2024<span class="heart"><i class="iconfont icon-heart"></i></span> <span class="author">FredTsang</span></span></div></footer><div class="back-to-top" id="back-to-top"><i class="iconfont icon-up"></i></div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/lib/jquery/jquery.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/lib/slideout/slideout.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/js/src/clipboard.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/js/src/clipboard-use.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/FredZeng/FredZeng.github.io@master/js/src/even.js?v="></script></body></html>
Loading

0 comments on commit 12c04bb

Please sign in to comment.