Hexo静态文件Git提交到自己的云服务器 搭建教程

Ydecl/忧

在服务器上搭建仓库

服务器:

1
2
3
4
5
6
7
8
9
10
11
12
13
mkdir hexo
cd hexo
git init --bare # 初始仓库

mkdir -p /root/html # 文件路径自定义

echo '#!/bin/bash' > hooks/post-receive
echo 'git --work-tree=/root/html --git-dir=/root/hexo checkout -f main' >> hooks/post-receive
#也可以直接写入:
#!/bin/bash
git --work-tree=/root/html --git-dir=/root/hexo checkout -f
#以上的路径自定义
chmod +x hooks/post-receive

保证自己的SSH 可以连接,必要时可以不用root。但是要保证仓库所属用户与git提交用户一致。

客户端:

1
2
3
4
5
6
7
8
#进入本地 public 文件夹,不想在public搭建仓库,记得改当前路径 和 git add .命令:
#在hexo项目根目录的使用 git add public
git init
git remote add origin root@你的服务器IP:/root/hexo #添加远程仓库地址
#windows 报错fatal: detected dubious ownership in repository at ...看下面常见问题解决方法
git add .
git commit -m "hexo"
git push -u origin master # 这里如果你改分支了master ,hooks/post-receive文件也需要更改 如 .....-f main

常见问题:

windows powershell添加远程仓库地址出现权限问题:

运行 git config --global --add safe.directory C:/hexo/public
这里写你的Hexo 下的 public 文件夹绝对路径

服务器没有文件/ hint: The ‘hooks/post-receive’ hook was ignored because it’s not set as executable.

权限问题: chmod +x hooks/post-receive

  • 标题: Hexo静态文件Git提交到自己的云服务器 搭建教程
  • 作者: Ydecl/忧
  • 创建于 : 2025-09-28 21:50:58
  • 更新于 : 2025-09-29 20:20:47
  • 链接: https://blog.yc2019.cn/posts/hexo-git.html
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
目录
Hexo静态文件Git提交到自己的云服务器 搭建教程