@52fhy
2015-07-05T10:46:26.000000Z
字数 4488
阅读 1831
hexo
git
修改 blog 目录下的 _config.yml 文件
打开 _config.yml 添加如下配置
deploy:
type: git
repo: git@github.com:xxx/xxx.github.io.git
branch: master
注意是git@github.com:xxx/xxx.github.io.git
形式的,不是https://github.com/yourname/blog.git
形式的。
然后安装插件hexo-deployer-git
支持git类型:
npm install hexo-deployer-git --save
再
hexo g #创建静态页面
hexo d #发布:清空.deploy_git/里文件,从public/复制新生成的文件
发布的时候会遇到一些问题。
这里假设你本地git环境已经搭建好(包括软件安装、ssh key创建),直接在cmd命令行会有些错误:
例如:
D:\Projects\nodejs\blog\source\_posts>hexo d
INFO Deploying: git
INFO Clearing .deploy folder...
INFO Copying files from public folder...
fatal: Not a git repository (or any of the parent directories): .git
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: fatal: Not a git repository (or any of the parent directories): .git
at ChildProcess.<anonymous> (D:\Projects\nodejs\blog\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:42:17)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Socket.<anonymous> (child_process.js:1183:11)
at Socket.emit (events.js:107:17)
at Pipe.close (net.js:485:12)
主要错误是fatal: Not a git repository (or any of the parent directories)
。没有对应的git仓库。
原因是hexo默认是以项目根目录下的.deploy_git
作为git仓库,所以我们得把这个仓库与线上的xxx.github.io
仓库绑定,如果绑定过其它目录下的仓库,可以直接把隐藏目录.git
复制到.deploy_git
目录下。
再次运行hexo d
:
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
已经进行类似git add
和git commit
操作了,但是没有提交成功,原因是没有权限:Permission denied (publickey)
。
在cmd命令行下直接运行没有提示输入ssh key密码。
好吧,还是在git Bash里提交一把吧:
YJC@YJC-PC /d/Projects/nodejs/blog/.deploy_git (master)
$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Enter passphrase for key '/c/Users/YJC/.ssh/id_rsa':
Counting objects: 49, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (20/20), done.
Writing objects: 100% (29/29), 8.52 KiB | 0 bytes/s, done.
Total 29 (delta 12), reused 0 (delta 0)
To git@github.com:52fhy/52fhy.github.io.git
96817f3..72dbf74 master -> master
这次提示输入key '/c/Users/YJC/.ssh/id_rsa'
并成功提交了。
也可以用cmder
等第三方软件代替cmd运行hexo -d
或者git push
命令。
C:\Users\YJC
λ d:
D:\Users\Documents\WindowsPowerShell\Modules\posh-git
λ cd /
D:\
λ cd .\Projects\nodejs\blog\.deploy_git
D:\Projects\nodejs\blog\.deploy_git [master]
D:\Projects\nodejs\blog
λ hexo g
INFO Files loaded in 5.48 s
INFO Generated: 2015/07/05/解决使用hexo -d提交不了blog的问题/index.html
INFO Generated: archives/index.html
INFO Generated: archives/page/2/index.html
INFO Generated: archives/2015/index.html
INFO Generated: archives/2015/page/2/index.html
INFO Generated: archives/2015/06/index.html
INFO Generated: archives/2015/07/index.html
INFO Generated: index.html
INFO Generated: page/2/index.html
INFO 58 files generated in 3.52 s
D:\Projects\nodejs\blog
λ hexo d
INFO Deploying: git
INFO Clearing .deploy folder...
INFO Copying files from public folder...
warning: LF will be replaced by CRLF in js/pc.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in 2015/07/05/解决使用hexo -d提交不了blog的问题/index.html.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in archives/2015/page/2/index.html.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in archives/page/2/index.html.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in page/2/index.html.
The file will have its original line endings in your working directory.
[master 0be220b] Site updated: 2015-07-05 10:26:50
9 files changed, 1390 insertions(+), 83 deletions(-)
create mode 100644 "2015/07/05/\350\247\243\345\206\263\344\275\277\347\224\250hexo -d\346\217\220\344\272\244\344\270\215\344\272\206blog\347\232\204\351\227\256\351\242\230/index.html"
create mode 100644 archives/2015/page/2/index.html
create mode 100644 archives/page/2/index.html
create mode 100644 page/2/index.html
warning: LF will be replaced by CRLF in 2015/07/05/解决使用hexo -d提交不了blog的问题/index.html.
The file will have its original line endings in your working directory.
Branch master set up to track remote branch master from git@github.com:52fhy/52fhy.github.io.git.
To git@github.com:52fhy/52fhy.github.io.git
72dbf74..0be220b master -> master
INFO Deploy done: git
D:\Projects\nodejs\blog
λ
也是可以的,很是方便。