前言

使用hexo在GitHub部署静态博客时,上传到仓库的是bianry文件(在.deploy_git中),无法直接查看源码。这里介绍一种方法,将源码也上传到仓库,方便查看。

使用多分支管理

  1. 在GitHub创建一个hexo分支,并将其设置为默认分支;

  2. 将其clone到本地,默认clone的是hexo分支内容,此时会包含一个.git文件夹,还有原本仓库中有的编译后的文件;

  3. 将原本仓库中的内容删除,只保留.git文件夹;

  4. 将原本的文件除了.deploy_git文件夹复制到本地仓库中;

  5. 在.gitignore文件中添加

    1
    2
    3
    4
    5
    6
    7
    .DS_Store
    Thumbs.db
    db.json
    *.log
    node_modules/
    public/
    .deploy*/

    如果clone过主题文件,需要把主题文件夹中的.git文件夹删除,因为不能嵌套clone

  6. 将clone的文件提交到hexo分支中;

    1
    2
    3
    git add .
    git commit –m add_branch
    git push

之后网站更新到main分支,源代码更新到hexo分支。

解决GitHub无法上传问题

1
2
3
kex_exchange_identification: Connection closed by remote host
Connection closed by 127.0.0.1 port 7890
fatal: Could not read from remote repository.
  • 使用代理或者不使用都会提示该问题
  • 之前使用正常

参考这个问题:
https://github.com/orgs/community/discussions/55269

最终解决方案:
~/.ssh/config中添加

1
2
3
Host github.com
Hostname 20.200.245.248
Port 443