github 和 coding 分别是国外和国内著名的 git 源代码管理平台,并且当前两个平台都支持 pages 功能。
github 和 coding 处理流程基本一致,下面的例子基本以 github 为例
注册帐号
去官网注册帐号
安装 Git
去 Git 官网下载安装即可。
注意:一般安装时使用默认路径,保证最终 Git 能把环境变量(Path)配置对。
以下所有命令行操作均在 git bash 下进行。
配置 Git SSH
1.检查电脑上现有的 SSH Key
cd ~/.ssh
如果提示:“No such file or directory” 说明你是第一次使用git。
2.生成新的 SSH Key
ssh-keygen -t rsa -C "you@youremail.com"
注意:Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):(回车就好),
Enter passphrase (empty for no passphrase):(回车,不需要输入密码)
Enter same passphrase again:(回车不需要输入密码)
因为Hexo的自动部署如果有密码的话会部署失败
3.添加 SSH Key 到 GitHub 和 Coding
cd ~/.ssh/ && ls
可以看到此目录下的文件:id_rsa id_rsa.pub
cat id_rsa.pub
将看到的内容复制下来(ssh-rsa开头)
分别在 GitHub 和 Coding 上找到配置公共 SSH Key 的地方,填上复制的 SSH Key 即可
4.测试访问
ssh -T git@github.com (测试 github)
ssh -T git@git.coding.net (测试 coding)
如果是以下提示:“Hi XXXX! You’ve successfully authenticated, but GitHub does not provide shell access.”
证明你配置成功了。
创建项目
在 GitHub 和 Coding 上创建和对应帐号用户名一致的项目名。
GitHub 上用户名为 krissss 则创建代码仓库名称为 krissss.github.io
Coding 上用户名为 kriss 则创建项目名称为 kriss
配置 Hexo 并进行一键部署安装
1.修改 hexo 目录下的 _config.yml
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
- type: git
repo: git@github.com:krissss/krissss.github.io.git
- type: git
repo: git@git.coding.net:kriss/kriss.git
2.部署上传
首次使用 hexo 需要安装上传依赖
npm install hexo-deployer-git --save
以后部署上传主需要使用以下命令
hexo generate -d
具体命令说明请参照官方说明
部署成功会显示类似以下信息:
Branch master set up to track remote branch master from git@git.coding.net:kriss/kriss.git.
To git@git.coding.net:kriss/kriss.git
* [new branch] HEAD -> master
INFO Deploy done: git
去 GitHub 和 Coding 代码仓库中查看即可看到已经上传的代码
查看 pages
GitHub 查看:
打开 krissss.github.io 即可看到部署完成的博客
Coding 查看:
Coding 需要在“具体项目=>Pages服务”开启
开启后打开 kriss.coding.me 即可看到部署完成的博客
- 本文作者: kriss
- 本文链接: http://www.kriss.pub/2016/07/01/hexo-git/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!
