[关闭]
@52fhy 2015-07-05T10:46:26.000000Z 字数 4488 阅读 1831

解决使用hexo -d提交不了blog的问题

hexo git


修改 blog 目录下的 _config.yml 文件
打开 _config.yml 添加如下配置

  1. deploy:
  2. type: git
  3. repo: git@github.com:xxx/xxx.github.io.git
  4. branch: master

注意是git@github.com:xxx/xxx.github.io.git形式的,不是https://github.com/yourname/blog.git形式的。

然后安装插件hexo-deployer-git支持git类型:

  1. npm install hexo-deployer-git --save

  1. hexo g #创建静态页面
  2. hexo d #发布:清空.deploy_git/里文件,从public/复制新生成的文件

发布的时候会遇到一些问题。
这里假设你本地git环境已经搭建好(包括软件安装、ssh key创建),直接在cmd命令行会有些错误:
例如:

  1. D:\Projects\nodejs\blog\source\_posts>hexo d
  2. INFO Deploying: git
  3. INFO Clearing .deploy folder...
  4. INFO Copying files from public folder...
  5. fatal: Not a git repository (or any of the parent directories): .git
  6. FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
  7. Error: fatal: Not a git repository (or any of the parent directories): .git
  8. at ChildProcess.<anonymous> (D:\Projects\nodejs\blog\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:42:17)
  9. at ChildProcess.emit (events.js:110:17)
  10. at maybeClose (child_process.js:1015:16)
  11. at Socket.<anonymous> (child_process.js:1183:11)
  12. at Socket.emit (events.js:107:17)
  13. 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

  1. Are you sure you want to continue connecting (yes/no)? yes
  2. Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts.
  3. Permission denied (publickey).
  4. fatal: Could not read from remote repository.

已经进行类似git addgit commit操作了,但是没有提交成功,原因是没有权限:Permission denied (publickey)
在cmd命令行下直接运行没有提示输入ssh key密码。
好吧,还是在git Bash里提交一把吧:

  1. YJC@YJC-PC /d/Projects/nodejs/blog/.deploy_git (master)
  2. $ git push
  3. warning: push.default is unset; its implicit value is changing in
  4. Git 2.0 from 'matching' to 'simple'. To squelch this message
  5. and maintain the current behavior after the default changes, use:
  6. git config --global push.default matching
  7. To squelch this message and adopt the new behavior now, use:
  8. git config --global push.default simple
  9. See 'git help config' and search for 'push.default' for further information.
  10. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
  11. 'current' instead of 'simple' if you sometimes use older versions of Git)
  12. Enter passphrase for key '/c/Users/YJC/.ssh/id_rsa':
  13. Counting objects: 49, done.
  14. Delta compression using up to 4 threads.
  15. Compressing objects: 100% (20/20), done.
  16. Writing objects: 100% (29/29), 8.52 KiB | 0 bytes/s, done.
  17. Total 29 (delta 12), reused 0 (delta 0)
  18. To git@github.com:52fhy/52fhy.github.io.git
  19. 96817f3..72dbf74 master -> master

这次提示输入key '/c/Users/YJC/.ssh/id_rsa'并成功提交了。

也可以用cmder等第三方软件代替cmd运行hexo -d或者git push命令。

  1. C:\Users\YJC
  2. λ d:
  3. D:\Users\Documents\WindowsPowerShell\Modules\posh-git
  4. λ cd /
  5. D:\
  6. λ cd .\Projects\nodejs\blog\.deploy_git
  7. D:\Projects\nodejs\blog\.deploy_git [master]
  8. D:\Projects\nodejs\blog
  9. λ hexo g
  10. INFO Files loaded in 5.48 s
  11. INFO Generated: 2015/07/05/解决使用hexo -d提交不了blog的问题/index.html
  12. INFO Generated: archives/index.html
  13. INFO Generated: archives/page/2/index.html
  14. INFO Generated: archives/2015/index.html
  15. INFO Generated: archives/2015/page/2/index.html
  16. INFO Generated: archives/2015/06/index.html
  17. INFO Generated: archives/2015/07/index.html
  18. INFO Generated: index.html
  19. INFO Generated: page/2/index.html
  20. INFO 58 files generated in 3.52 s
  21. D:\Projects\nodejs\blog
  22. λ hexo d
  23. INFO Deploying: git
  24. INFO Clearing .deploy folder...
  25. INFO Copying files from public folder...
  26. warning: LF will be replaced by CRLF in js/pc.js.
  27. The file will have its original line endings in your working directory.
  28. warning: LF will be replaced by CRLF in 2015/07/05/解决使用hexo -d提交不了blog的问题/index.html.
  29. The file will have its original line endings in your working directory.
  30. warning: LF will be replaced by CRLF in archives/2015/page/2/index.html.
  31. The file will have its original line endings in your working directory.
  32. warning: LF will be replaced by CRLF in archives/page/2/index.html.
  33. The file will have its original line endings in your working directory.
  34. warning: LF will be replaced by CRLF in page/2/index.html.
  35. The file will have its original line endings in your working directory.
  36. [master 0be220b] Site updated: 2015-07-05 10:26:50
  37. 9 files changed, 1390 insertions(+), 83 deletions(-)
  38. 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"
  39. create mode 100644 archives/2015/page/2/index.html
  40. create mode 100644 archives/page/2/index.html
  41. create mode 100644 page/2/index.html
  42. warning: LF will be replaced by CRLF in 2015/07/05/解决使用hexo -d提交不了blog的问题/index.html.
  43. The file will have its original line endings in your working directory.
  44. Branch master set up to track remote branch master from git@github.com:52fhy/52fhy.github.io.git.
  45. To git@github.com:52fhy/52fhy.github.io.git
  46. 72dbf74..0be220b master -> master
  47. INFO Deploy done: git
  48. D:\Projects\nodejs\blog
  49. λ

也是可以的,很是方便。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注