@52fhy
        
        2015-07-05T02:46:26.000000Z
        字数 4488
        阅读 1954
    hexo git
修改 blog 目录下的 _config.yml 文件 
打开 _config.yml 添加如下配置
deploy:type: gitrepo: git@github.com:xxx/xxx.github.io.gitbranch: 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 dINFO Deploying: gitINFO Clearing .deploy folder...INFO Copying files from public folder...fatal: Not a git repository (or any of the parent directories): .gitFATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.htmlError: fatal: Not a git repository (or any of the parent directories): .gitat 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)? yesWarning: 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 pushwarning: push.default is unset; its implicit value is changing inGit 2.0 from 'matching' to 'simple'. To squelch this messageand maintain the current behavior after the default changes, use:git config --global push.default matchingTo squelch this message and adopt the new behavior now, use:git config --global push.default simpleSee '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.git96817f3..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_gitD:\Projects\nodejs\blog\.deploy_git [master]D:\Projects\nodejs\blogλ hexo gINFO Files loaded in 5.48 sINFO Generated: 2015/07/05/解决使用hexo -d提交不了blog的问题/index.htmlINFO Generated: archives/index.htmlINFO Generated: archives/page/2/index.htmlINFO Generated: archives/2015/index.htmlINFO Generated: archives/2015/page/2/index.htmlINFO Generated: archives/2015/06/index.htmlINFO Generated: archives/2015/07/index.htmlINFO Generated: index.htmlINFO Generated: page/2/index.htmlINFO 58 files generated in 3.52 sD:\Projects\nodejs\blogλ hexo dINFO Deploying: gitINFO 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:509 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.htmlcreate mode 100644 archives/page/2/index.htmlcreate mode 100644 page/2/index.htmlwarning: 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.git72dbf74..0be220b master -> masterINFO Deploy done: gitD:\Projects\nodejs\blogλ
也是可以的,很是方便。