簡介
Git-ftp 是一個(gè)使用 git 作為版本控制的 ftp 應(yīng)用,它可以根據(jù) git 的改動(dòng)只上傳需要更新的文件,來節(jié)省流量和時(shí)間。
安裝
在 Debian 系下,只需要安裝:
sudo apt install git-ftp
其他版本具體可以在這里找到https://github.com/git-ftp/git-ftp/releases只需要解壓運(yùn)行即可。
使用
添加 Config
可以直接在 git 項(xiàng)目的.git/config 里添加:
[git-ftp]
url = ftp.example.net
user = ftp-user
password = secr3t
或者使用 git 命令來添加:
git config git-ftp.url ftp.example.net
git config git-ftp.user ftp-user
git config git-ftp.password secr3t
具體 Config 參數(shù)
git config git-ftp.url ftp://ftp.example.net:8010/path ftp 地址
git config git-ftp.user ftp-user ftp 用戶名
git config git-ftp.password secr3t ftp 密碼
git config git-ftp.syncroot path/dir 本地需要同步的目錄
git config git-ftp.remote-root htdocs 遠(yuǎn)程目錄
更多可以查看這里-> manual
同步
初始化同步所有文件
git ftp init
其他用法很簡單,只需要在 git 內(nèi)提交文件,然后使用
gti ftp push
就可以同步到遠(yuǎn)程目錄了,在 ftp 內(nèi)會(huì)產(chǎn)生一個(gè) .git-ftp.log 的文件用來記錄 ftp 內(nèi)文件的 commit 版本,然后通過于本地 git 比較從而只上傳更新的部分。
同步 Hugo
本來博客是使用 Caddy + git + hugo 進(jìn)行同步,后因?yàn)?VPS 只跑這一個(gè)程序有點(diǎn)浪費(fèi)了,正巧百度云的虛擬主機(jī)打折一年只要30元,于是搬到到虛擬主機(jī)上。(2019-07開始簡書之旅)
同步的話,按照上面的內(nèi)容添加好 ftp 后,將 ./public 目錄移出 .gitignore 文件里面, git-ftp.syncroot 的路徑應(yīng)該是$PATH_TO_YOUR_HUGO/public,然后使用hugo -E 生成 public 里的文件,提交更改后,使用 git ftp push 就可以同步了。