之前在家里搭建了博客,成功部署到github上,並將hexo目錄也上傳至github/hexo倉庫保存。
后來到公司想把它們down下來,方便兩邊修改同步。
第一個坑是hexo發布博客到github
同樣進行了一系列的node安裝,hexo安裝等,並且在hexo博客目錄下down下了guthub/hexo的資源,本地啟動,沒問題。
但是當我發布想發布到yourname.github.io上時,問題來了,它居然把我的整個hexo博客目錄扔到了yourname.github.io上,不是說好的只發布.deploy_git下的內容呢!!
於是我就茫然了啊,我去查看hexo下的_config.yml文件,
deploy:
type: git
repo: git@github.com:tenny-peng/tenny-peng.github.io.git
branch: master
沒錯啊,是這個地址啊。
后來一想也不對,就算這里錯了也不對,不是目標地址錯了,而是發布的內容錯了。
網上查到了這篇博客: hexo部署到github遇到的坑,最后說刪除hexo目錄下的.git文件,然后我就試了試,重新發布,然后又報錯了。。這里想截圖可是命令行找不到了,大概就是說沒有指定repository,然后我點開.deploy_git文件夾,突然想到在家里.deploy_git文件夾下面是有.git的,而且還是我自己指定的。
哈哈,瞬間好像知道了,打開git bash,切換到hexo/.deploy_git,執行
git init
再綁定遠程倉庫
git remote add origin git@github.com:tenny-peng/tenny-peng.github.io.git
回到cmd命令行
hexo d
搞定了,成功提交了正確的博客內容。
第二個坑是hexo目錄與github/hexo同步
然后再把我的hexo目錄和github/hexo同步,剛才把hexo目錄下的.git刪了。好吧,重新建回來。
git bash切換到hexo根目錄
git init
git remote add origin git@github.com:tenny-peng/hexo.git
執行pull指令
$ git pull origin master
From github.com:tenny-peng/hexo
* branch master -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
.npmignore
_config.yml
db.json
node_modules/.bin/JSONStream
node_modules/.bin/JSONStream.cmd
node_modules/.bin/acorn
node_modules/.bin/acorn.cmd
...
這里說一下,第一個坑中hexo目錄下的內容是我直接從github/hexo上down下來復制過來的,然后本地又進行過hexo生成和發布操作,錯誤具體原因不太清除(知道的童鞋歡迎指正),網上查到解決辦法是先清理
$ git clean -f -d
Skipping repository .deploy_git/
Removing .npmignore
Removing _config.yml
Removing db.json
Removing node_modules/
Removing package.json
Removing public/
Removing scaffolds/
Removing source/
Removing themes/
清理后hexo目錄下只剩.deploy_git和.git目錄,再拉取就可以了
$ git pull origin master
From github.com:tenny-peng/hexo
* branch master -> FETCH_HEAD
Checking out files: 100% (7651/7651), done.
所以下次可以先同步好hexo文件夾,這樣第二個坑應該就不會出現了。