• 请不要在回答技术问题时复制粘贴 AI 生成的内容
ntpok
V2EX  ›  程序员

GitHub Pages 必备技巧:删除“commit”记录

  •  
  •   ntpok · Jun 8, 2018 · 8918 views
    This topic created in 3074 days ago, the information mentioned may be changed or developed.
    倒腾了一个 NTP 监控的工具 http://www.ntpok.com/ ——检测结果发送到 GitHub Pages。每隔十分钟就更新一次,数据量很小。后来突然卡住了,更新不了了。发现是“ commit ”记录太多,国内网络环境不行,卡死。

    彻底删除所有“ commit ”记录:
    https://github.com/ntpok/ntpok/blob/master/ntpok-update.sh (欢迎 star )
    代码 11 行到 16 行。

    原理:把“.git ”目录整个删除,然后再次发送到 GitHub。

    效果:在 https://github.com/ntpok 看到“ commit ”统计次数已经超过一千次,但是在 https://github.com/ntpok/ntpok.github.io 总是只有一个“ commit ”。
    Supplement 1  ·  Jun 9, 2018
    更新了脚本,清空“ commit ”记录的代码在:
    https://github.com/ntpok/ntpok/blob/master/ntpok-update.sh
    代码 17 行到 22 行
    16 replies  •  2018-06-09 10:22:44 +08:00
    Aoang
    Aoang
    Jun 8, 2018 via Android
    1
    这是 git 常识吧,怎么就成了必备技巧了
    ntpok
    ntpok
    OP
    Jun 8, 2018
    2
    @Aoang 这东西是“必备技巧”,同时也是“常识”——两者不矛盾呀 :-)
    Aoang
    Aoang
    Jun 8, 2018 via Android
    3
    我 github 上是私有仓库,我找个其他的给你看看。

    https://github.com/Hanxv/Blog/blob/master/.travis.yml
    Richardweii
    Richardweii
    Jun 8, 2018 via Android
    4
    自动 rebase squash 或者 fixup 到第一个 commit 不就好了吗
    ntpok
    ntpok
    OP
    Jun 8, 2018
    5
    @Aoang 是的,这个应该也能做到“没有 commit 历史记录”,也是“ git init ”然后“ push ”过去了。
    ntpok
    ntpok
    OP
    Jun 8, 2018
    6
    @Richardweii “ rm -rf .git ”最直接啦,个人意见哈。
    pexcn
    pexcn
    Jun 8, 2018
    7
    rebase & force push?
    ntpok
    ntpok
    OP
    Jun 8, 2018❤️1
    8
    @pexcn 没有说这是唯一方法哈,只是觉得“ rm -rf .git ”很合胃口 :-)
    shenqi
    shenqi
    Jun 8, 2018
    9
    等你的 page 有几百兆,你就不会这么操作了。管他多少个 commit 呢。
    BFDZ
    BFDZ
    Jun 8, 2018
    10
    有 ss,没卡过
    ntpok
    ntpok
    OP
    Jun 8, 2018
    11
    @shenqi 到了“几百兆”,估计只能 SS 了,国内网络就这样。
    ntpok
    ntpok
    OP
    Jun 8, 2018
    12
    @BFDZ 咱们尽量不用 SS 哈。
    wly19960911
    wly19960911
    Jun 8, 2018
    13
    那么 git clone --depth=1 能解决这个问题吗?
    hash
    hash
    Jun 9, 2018 via iPhone
    14
    --depth 才是正解,直接删除.git 真的太 hard 了
    ntpok
    ntpok
    OP
    Jun 9, 2018
    15
    @wly19960911 是的,“ depth ”可以解决这个问题。
    ntpok
    ntpok
    OP
    Jun 9, 2018
    16
    @hash 个人意见:“直接删除.git ”是最“直接”的方法。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1760 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 14:25 · PVG 22:25 · LAX 06:25 · JFK 09:25
    ♥ Do have faith in what you're doing.