快乐的老鼠 发表于 2018-1-13 06:19:25

git-ftp 用git管理ftp空间

  ftp管理不能实现版本控制,而且多电脑工作时,同步很成问题。
  git-ftp可以完美的解决问题
  下面是我的趟坑之路,本机的环境是win10,首先你的机器得装有git。
  git-ftp的地址https://github.com/git-ftp/git-ftp/
  一、安装git-ftp
  查看install.md文件中关于windows的内容;主要说的是下载带sftp支持的curl,但实际上新版git装完,git bash里的curl支持sftp
  在git bash中
  

$ curl -V  
curl
7.53.0 (x86_64-w64-mingw32) libcurl/7.53.0 OpenSSL/1.0.2k zlib/1.2.11 libssh2/1.8.0 nghttp2/1.19.0 librtmp/2.3  
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smtp smtps telnet tftp
  
Features: IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL libz TLS
-SRP HTTP2 HTTPS-proxy Metalink  

  你会发现是支持sftp的,不用再安装curl直接在git bash中执行
  

curl https://raw.githubusercontent.com/git-ftp/git-ftp/master/git-ftp > /bin/git-ftp  
chmod 755 /bin/git-ftp
  

  如果提示bash: /bin/git-ftp: Permission denied,那么请用管理员权限运行git bash
  我理解以上步骤就是复制git-ftp文件到git/usr/bin下,应该可以直接在github上下载git-ftp到git/usr/bin下,但我没试过,有兴趣可以试验下,告诉我结果。
  二、创建git仓库
  在你要创建仓库的目录下执行,在cmd或git bash中都可以,文档中只说了git config,但在这之前
  必须先git init创建一个空的仓库,否则没有.git文件夹,是不能执行git config的
  

git init  
git config git
-ftp.url ftp.example.net  
git config git
-ftp.user ftp-user  
git config git
-ftp.password secr3t  

  在你的仓库下.git目录下有个config文件,里面可以设置url,user,password
  

  bare
= false  repositoryformatversion
= 0  filemode
= false  symlinks
= false  ignorecase
= true  logallrefupdates
= true  
[git
-ftp]  url
= url  user
= yourusername  password
= yourpassword  

  三、进阶安装lftp
  因为git-ftp 的有些命令(git ftp download;git ftp pull)需要用到lftp,所以需要安装lftp
  在 git bash 中执行
  

chcon install lftp --version 4.7.5  

  安装lftp
  可以到 https://nwgat.ninja/lftp-for-windows/ 查看最新的lftp版本,也可以下载安装复制到git/urs/bin下,但可能会有冲突,没有自动安装好
  四、git ftp 命令
  https://github.com/git-ftp/git-ftp/blob/master/man/git-ftp.1.md
  最好是看看上面的连接说的比较详细
  我理解:git ftp是通过远程创建.git-ftp.log文件进行版本管理的。
  git ftp init 用于本地有提交,远程ftp url为空,上传所有提交到远程并创建.git-ftp.log
  git ftp catchup 用于远程有内容,本地是空库,在远程创建.git-ftp.log,再git ftp download
  常用
  git ftp pull 拉取
  git ftp push 推送
  五、创建批处理文件,方便执行
  在仓库目录下建一个pull.bat文件写入
  

git ftp pull  

  在仓库目录下建一个push.bat文件写入
  

git ftp push  

  这样就可以每次执行.bat 文件不用打命令了
页: [1]
查看完整版本: git-ftp 用git管理ftp空间