换电脑后怎么把博客环境搬过去?两种情况都帮你安排明白。


前置准备:新电脑要装什么

不管哪种情况,新电脑都需要先装好这些:

1
2
3
4
5
6
7
8
9
10
11
12
# CachyOS / Arch Linux
sudo pacman -S git nodejs npm

# Ubuntu / Debian
sudo apt install git nodejs npm

# macOS
brew install git node

# Windows(用 winget 一键装)
winget install Git.Git
winget install OpenJS.NodeJS

然后配置 git 和 GitHub 认证(参考本站另一篇 GitHub PAT 教程)。


情况一:没存 U 盘 / 网盘

前提:源码已推送到 GitHub(hexo_blog-source 仓库)

步骤

1
2
3
4
5
6
7
8
9
# 1. 克隆源码仓库
git clone https://github.com/SEYYl/hexo_blog-source.git
cd hexo_blog-source

# 2. 切到 source 分支
git checkout source

# 3. 安装 Hexo 及所有依赖
npm install

4. 检查主题

Solitude 主题可能通过两种方式管理:

1
2
3
4
5
# 方式 A:如果是 git submodule
git submodule update --init --recursive

# 方式 B:如果是直接放在 themes/ 里(已随源码 push)
ls themes/solitude/ # 能看到文件就说明齐了

5. 添加 hexo 部署用的 remote

源码仓库配了两个 remote,新电脑需要重新添加 public remote:

1
2
3
4
5
6
# 查看已有 remote
git remote -v
# 应该只有 origin

# 添加 public remote(用于 hexo deploy)
git remote add public https://github.com/SEYYl/hexo_blog.git

6. 验证

1
2
3
4
5
# 本地预览
npx hexo server # http://localhost:4000

# 检查能否部署
npx hexo deploy # 第一次会提示输入 GitHub PAT

情况二:有备份(U 盘或网盘)

虽然手动备份了,但最好还是和 GitHub 同步一下,避免版本混乱。

步骤

1
2
3
# 1. 把备份复制到新电脑
cp -r /路径/U盘或网盘/boke1.0/boke /home/你的名字/下载/boke/
cd /home/你的名字/下载/boke/

2. 确认 git remote

1
git remote -v

应该能看到:

1
2
origin   https://github.com/SEYYl/hexo_blog-source.git (fetch)
origin https://github.com/SEYYl/hexo_blog-source.git (push)

如果没有,重新添加:

1
2
git remote add origin https://github.com/SEYYl/hexo_blog-source.git
git remote add public https://github.com/SEYYl/hexo_blog.git

3. 和 GitHub 同步(关键步骤)

备份可能比 GitHub 上的版本旧,也可能新,先确认:

1
2
3
4
5
6
# 拉取远程最新状态
git fetch origin

# 查看本地和远程的差异
git log origin/source..HEAD # 本地有但远程没有的提交
git log HEAD..origin/source # 远程有但本地没有的提交

如果本地比远程新(备份时没 push):

1
git push origin source

如果远程比本地新(其他电脑上改过):

1
git pull origin source

如果有冲突:

1
2
git pull origin source --rebase
# 解决冲突 → git add . → git rebase --continue

4. 安装依赖

1
npm install

5. 验证

1
2
npx hexo server
npx hexo deploy

两种方案对比

情况一:无备份 情况二:有备份
速度 慢(下载依赖) 快(依赖可能已装好)
安全性 100% 来自 GitHub 需手动同步
推荐度 ⭐⭐⭐ 推荐 ⭐⭐ 备用
前提 源码已 push U 盘/网盘里有最新源码

建议:平时用情况一(纯从 GitHub 克隆),省心。U 盘备份当作「最终保险」,不用频繁更新。


从零开始的完整 checklist

1
2
3
4
5
6
7
8
9
10
□ 装 git、node、npm
□ 配置 git 用户名和邮箱
□ 配置 GitHub PAT 认证
□ 克隆 hexo_blog-source(或复制备份)
□ 切到 source 分支
□ 配置 git remote(origin + public)
□ npm install 安装依赖
□ 检查 themes/solitude/ 是否完整
□ npx hexo server 预览
□ npx hexo deploy 部署上线

一句话总结:
源码在 GitHub 上 = 随时可以搬家。U 盘备份是保险,但不是必需品。