用安卓手机的 Termux 更新 Hexo 博客
起因
本博客使用 Butterfly 主题,最近 Butterfly 从 3.8.4 更新到了 4.0.1。要更新主题,有电脑的时候,可以直接用 Github Desktop+Git Bash,然而我身边只有手机,没法使用 Github Desktop 更新 Github 上的博客源码。所以想着用手机更新博客。
- 开端
- 发展
- 高潮
- 结尾
开端
工欲善其事必先利其器,首先下载安卓模拟终端 Termux。
更换为清华源
1 | sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list |
安装包
1 | pkg install vim curl wget git unzip unrar nodejs-lts openssh -y && npm install hexo-cli -g |
发展
配置 Personal access tokens
如果你的博客是公共仓库,你可以跳过这段,如果是私有仓库,则必须配置 Personal access tokens。下面是配置 Github Personal access tokens 的过程。
- 登陆 Github。
- 转到 Settings/Developer settings/Personal access tokens。
- 点 Generate new token。
- 设置有效时间,Scopes 全选上。
- 最后点 Generate token,复制保存好 token,待会验证 Github 账号需要它。
克隆仓库
1 | git clone https://github.com/用户名/仓库名.git |
如果仓库私有,接着输入用户名,在 Password 一行填刚刚的 token。
1 | cd 仓库名 |
检查
1 | hexo clean && hexo g && hexo s |
如果不出意外的话,浏览器打开 http://localhost:4000 ,就能看到博客内容了。
高潮
首次准备
为当前博客目录配置用户和邮箱:
1 | git config user.name 用户名 |
添加远程地址:
1 | git remote add origin git@github.com:用户名/仓库名.git |
主要过程
克隆完仓库,对它操作后,用 git status
查看工作区与暂存区的差异(项目的改变)。
接着将改变从工作区添加到暂存区。
用 git add .
直接添加全部。
接着将暂存区的文件提交至本地库并添加注释。
1 | git commit -m "手机更新" |
最后,将本地库的项目推至远程库。
1 | git push origin 分支名 # 分支名可以是 master/main 等 |
一些报错
- 可能不存在
push
的分支。
1 | error: src refspec master does not match any |
- 有较新的提交,需要先
pull
。
1 | ! [rejected] 分支名 -> 分支名 (fetch first) |
解决方法:
1 | git pull --rebase origin 分支名 |
结尾
从本地到云端:
1 | git status |
从云端到本地:
1 | git fetch origin 分支名 && git merge origin/分支名 |
如果不确定哪边的内容最新用 git log origin/分支名
查看最近提交记录。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 CasecoRI & 小破站!
评论
GiscusTwikoo