0%

不同电脑上同步Hexo Blog

前天在实验室弄好这个Blog, 后来回到宿舍就有个问题: 怎么在宿舍更新我的博客, 然后同步上去? 难道每次都要到实验室电脑上写博客?这也太不方便了. Google一下, 找到了这个解决办法, 思路就是在github上再新建一个repository, 用来同步博客.

假定在电脑A上成功搭建了博客, 也同步到了github上的仓库username.github.io 现在想在电脑B上也能更新博客, 并同步到github上. 过程如下:

首先, 在github上再键一个repository, 假定为HexoBlog. 进到电脑A上的博客的文件夹. 如果你的博客主题是从github上克隆下来的, 要把主题文件夹里的.git文件夹删掉. 以我自己的为例, 我用的主题是yilia, 用 ls -la命令就看到 thems/yilia/ 下面的隐藏文件夹.git. 然后删掉.

1
2
ls -la themes/yilia
rm -rf themes/yilia/.git

好了, 接下来用github同步整个博客文件夹

1
2
3
git init
git add .
git commit -m "First commit"

这就完成了在电脑A上用git对博客文件夹进行管理, 接下来同步到刚刚新建的repository, 也就是HexoBlog

1
git remote add origin git@github.com:username/HexoBlog.git

上面username换成你自己的github用户名, HexoBlog换成刚刚新建的repository名字. 最后, push到github.

1
git push origin master

上面是在电脑A上做的工作,接下来回到电脑B. 首先, 像在电脑A上搭建博客一样, 要在B上安装git, node.js, hexo 安装过程自己Google(既然在A上搭好博客了,安装过程应该会了). 然后把github上的repository克隆到电脑B上
1
git clone git@github.com:username/HexoBlog.git
按照Blog目录下自带的.gitignore文件, node_modules文件夹是不会同步的, 所以同步之后需要自己再次进行
1
npm install

这样, 在电脑B上写了新文章后, 更新到github上的 username.github.io

1
2
hexo g
hexo d

然后, 更新到github上的 HexoBlog (即刚刚新建的用来同步整个博客文件夹的repository)

1
2
git add .
git push

这样, 就可以在不同电脑上同步博客了.

hexo上有两个issue可以参考
issue527
issue752

@至善园