hexo博客源码备份(git版本控制)

在github建立私有仓库:仓库名(自己命名)

在Blog文件夹下进行git bash

1
2
3
4
5
6
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:name/仓库名.git
git push -u origin main

注意:推送之后记得删除.git文件夹,不然会影响hexo d部署

换设备或文件丢失后版本回滚

1
git clone https://github.com/name/仓库名.git

打开克隆的文件夹,git bash

安装依赖

1
npm install

本地生成,预览

1
2
hexo g
hexo s

完毕!


添加或修改代码,文件后再次推送出现:

[rejected] main -> main (fetch first) error: failed to push some refs to 'github.com:

解决办法:

1
2
3
4
5
6
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:name/仓库名.git
git push origin main --force

一定要删除.git文件夹,切记切记!!!

git push origin main --force会覆盖之前的版本,不安全。

正确做法及原理移步这里的多人协作和Rebase部分