更换电脑Hexo博客迁移

上传电脑中博客的源文件

1.生成的静态网页(.deploy_git)放在master分支在paranoiddeon.github.io 新建hexo分支存放博客源文件(除.deploy_git外的文件),在该仓库的setting>branch>default branch设为hexo。在本地任意目录打开git bash:

1
git clone [email protected]:paranoiddeon/paranoiddeon.github.io.git

2.在克隆到本地的paranoiddeon.github.io中,把除了.git 文件夹外的所有文件都删掉。把之前博客文件夹中除了.deploy_git的文件全部复制到paranoiddeon.github.io中,删除theme文件夹中可能存在的.git 文件夹,避免嵌套上传失败。之后把博客的源文件上传到hexo分支:

1
2
3
git add .
git commit –m "add branch"
git push

3.因为之前博客使用的主题是从第三方仓库clone的,在执行git add .的时候出现了”fatal: in unpopulated submodule maupassuant” 错误,导致主题文件夹没有被上传,所以需要删除再重新add该目录,在theme目录中执行:

1
2
git rm -rf --cached maupassuant  //删除文件夹
git add maupassuant

在新电脑(Windows)重新搭建环境

1.下载安装Git

2.设置git全局邮箱和用户名

1
2
git config --global user.name "yourgithubname"
git config --global user.email "yourgithubemail"

3.设置ssh key

1
2
3
4
5
ssh-keygen -t rsa -C "youremail"
Are you sure you want to continue connecting (yes/no)?
#输入yes 生成后填到github 在提示的文件目录复制id_rsa.pub 添加到github(settings>SSH keys)
#验证是否成功
ssh -T [email protected]

4.下载安装nodejs
5.安装hexo

1
npm install hexo-cli -g

6.在新电脑clone博客源文件
1
git clone [email protected]:paranoiddeon/paranoiddeon.github.io.git

7.安装hexo-deployer-git

1
2
3
4
5
cd paranoiddeon.github.io
npm install
npm install hexo-deployer-git --save
//用于将 public 目录中的文件和目录推送至 _config.yml 中指定的远端仓库和分支中,
//并且完全覆盖该分支下的已有内容。

8.生成部署博客网页

1
2
hexo g
hexo d

如果在多台电脑上同步博客,写完上传到远程仓库

1
2
3
git add .  //所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new)
git commit –m "xxxx" //将暂存区里的改动给提交到本地的版本库。
git push //将本地版本库的分支推送到远程服务器上对应的分支

在另一台电脑pull
1
git pull//取回远程主机某个分支的更新,再与本地的指定分支合并