hexo 多 PC 同步
由于手上有一笔记本,一台式机,不想拷来拷去麻烦,便研究 hexo 的多 PC 同步,网上看了很多,都是通过 Github 来同步,但是有一问题是,Github 免费仓需要公开代码,这样一来包括博客的配置文件都会公开,所以便研究如何通过 git 备份到自己的 VPS 上来。以下是总结。
我之前配置 hexo 自动部署的时候,已经在 VPS 上配置好了 git 服务端和 git 用户,这里便不在叙述。
首先在服务器创建 git 仓库 进入 repo 文件夹,输入下列命令
mkdir hexo.git && hexo.git
git init --bare
然后在本地博客目录下新建 git 仓库, 并编辑 .gitignore
文件
.gitignore
文件内的目录或文件名将不会备份
git init
git remote add origin <server>
remote add
操作会将本地仓库映射到云端origin
是本地分支<server>
是指在线仓库的地址
git add .
git commit -m "first"
git push -u origin master
至此备份的工作便完成了,赶紧去 clone
一份下来,运行 npm install
检查了一下发现主题只备份了一个文件夹,里面是空的,又一番搜索发现需要使用 subtree
的方式来备份主题
首先删除本地的主题,注意保存已修改的 _config.yml
文件
然后绑定子项目,以 hexo-theme-new-vno主题为例
git remote add -f vno git@[email protected]:monniya/hexo-theme-new-vno.git
git subtree add --prefix=themes/vno vno master --squash
现在在主项目中 push
就可以方便的同步主题和配置了。