利用Git版本管理将只修改过的文件上传到FTP服务器 支持SFTP协议

2018-04-16 09:31:00
git
转贴:
吕滔博客
1160

如果你平时使用 Git管理你的代码,并且很不巧,你的 服务器管理员又只给了你一个 FTP权限。又或者,你没在服务器上跑CI,那你来对地方了,今天我们隆重介绍GIT-FTP工具, 开源地址

先简单的说下使用,然后我们再详解

# 配置
git config git-ftp.url "ftp://ftp.lvtao.net:21/public_html"
git config git-ftp.user "ftp-user"
git config git-ftp.password "secr3t"
# 上传所有文件
git ftp init
# 或者覆盖文件
git ftp catchup
# 上传修改的新文件
echo "new content" >> index.txt
git commit index.txt -m "Add new content"
git ftp push

好了,我们从安装开始...

安装篇

编译

安装

git clone https://github.com/git-ftp/git-ftp.git
cd git-ftp
# choose the newest release
tag="$(git tag | grep '^[0-9]*\.[0-9]*\.[0-9]*$' | tail -1)"
# checkout the latest tag
git checkout "$tag"
sudo make install

更新

git fetch
git checkout "$(git tag | grep '^[0-9]*\.[0-9]*\.[0-9]*$' | tail -1)"
sudo make install

Debian, Ubuntu 使用apt

安装

sudo apt-get install git-ftp

如果你想要Git-ftp维护的最新版本,可以添加PPA:

sudo -s
add-apt-repository ppa:git-ftp/ppa
# On Debian, you need to modify the sources list to use the same PPA
source /etc/*-release
if [ "$ID" = "debian" ]; then
    dist="$(echo /etc/apt/sources.list.d/git-ftp-ppa-*.list | sed 's/^.*ppa-\(.*\)\.list$/\1/')"
    sed -i.backup "s/$dist/precise/g" /etc/apt/sources.list.d/git-ftp-ppa-*.list
fi
apt-get update

MacOS

安装

xcode-select --install
brew install git
brew install curl --with-libssh2
brew install brotli
brew install git-ftp

更新

brew upgrade git-ftp

Windows

不会...

使用

FTP

git ftp init -u "memory" -P "ftp://ftp.lvtao.net/public_html"

SFTP

git ftp init -u "memory" --key "$HOME/.ssh/id_rsa" "sftp://lvtao.net/var/www/public_html"

配置

git config git-ftp.<(url|user|password|syncroot|cacert|keychain|...)> <value>

示例

$ git config git-ftp.user john
$ git config git-ftp.url ftp.example.com
$ git config git-ftp.password secr3t
$ git config git-ftp.syncroot path/dir
$ git config git-ftp.cacert caCertStore
$ git config git-ftp.deployedsha1file mySHA1File
$ git config git-ftp.insecure 1
$ git config git-ftp.key ~/.ssh/id_rsa
$ git config git-ftp.keychain user@example.com
$ git config git-ftp.remote-root htdocs

更多使用请参考man/git-ftp.1.md下使用手册

发表评论
评论通过审核后显示。