hexo -d命令只會在GitHub上面部署生成的html,css,js等網頁相關文件,而hexo源文件則仍然保存在服務器/本機上,這不利於hexo博客的搬遷。實際上,我們可以在GitHub上的hexo博客倉庫裏創建一個
hexo分支
保存所有的hexo源文件
,這樣以後在其它服務器上我們可以通過git clone
實現hexo博客一鍵移植
在之前username.github.io倉庫裏新建hexo分支
點擊Branch
輸入hexo
,即可創建hexo分支
因爲我已經創好hexo分支了,所以這裏創建分支a示例:
將hexo設爲默認分支
爲了簡化後面的部署,建議hexo設爲默認分支
settings->Branches
服務器git clone該倉庫
指定目錄下clone該項目,這裏我選擇的是/opt/hexo_surce
,hexo
爲之前hexo源文件
的目錄
[root@iZwz93tzhqv97y8089coonZ opt]# pwd
/opt
[root@iZwz93tzhqv97y8089coonZ opt]# git clone https://github.com/html1211/html1211.github.io.git hexo_source
[root@iZwz93tzhqv97y8089coonZ opt]# ls
hexo hexo_source nodejs
刪除hexo分支下原有內容
由於新建的hexo分支會與之前master分支內容一致(保存的是靜態網頁
),hexo分支
不需要存放這些文件
git rm -r <file>
刪除所有倉庫文件(.git除外
)
[root@iZwz93tzhqv97y8089coonZ hexo_source]# ls -a
. .. 2020 about archives atom.xml categories css .git images index.html js lib live2dw schedule search.xml tags
[root@iZwz93tzhqv97y8089coonZ hexo_source]# git rm -r 2020 about archives atom.xml categories css images index.html js lib live2dw schedule search.xml tags
設置git origin
git remote add origin https://github.com/username/username.github.io.git
複製hexo源文件到hexo_source目錄
檢查一下hexo目錄下是否有.git
和,有的話刪除它,不然它會覆蓋hexo_source
目錄下b的.git
,
本地hexo_source倉庫
就會失效
同時,如果hexo某個子目錄存在.git
文件,那麼這個子目錄將無法git add到緩存區
提交到GitHub
一般來說
hexo/themes/next
目錄會有.git
文件(因爲之前是通過git clone下載的next主題
)
hexo/source/lib/canvas-nest
目錄會有.git
(安裝了這個插件的話
)
保險起見,查找所有.git文件
find / -name .git
如果是在hexo/
目錄下的話,rm -rf
刪除它們
爲了簡單,我們直接拷貝hexo目錄下所有文件至hexo_source
/bin/cp -rf hexo/. hexo_source
git提交hexo源文件
git add -f
強制提交所有源文件(包括非版本控制文件
)
[root@iZwz93tzhqv97y8089coonZ hexo_source]# ls
_config.yml db.json node_modules package.json package-lock.json public scaffolds source themes
[root@iZwz93tzhqv97y8089coonZ hexo_source]# git add -f _config.yml db.json node_modules package.json package-lock.json public scaffolds source themes
git commit -m "add hexo source files"
git提交文件至hexo分支
git push origin hexo
這樣,你的所有hexo源文件
放在了參倉庫的hexo分支
移植新服務器
在新服務器下指定目錄git clone 倉庫hexo源文件
git clone https://github.com/html1211/html1211.github.io.git hexo
甚至可以刪除當前服務器下原來的hexo目錄,在當前服務器hexo_source目錄下
開發,hexo g
生成靜態網頁
通過hexo d
部署到倉庫的master分支
通過git add -u
,git commit -m ""
,git push origin hexo
部署到倉庫的hexo分支