将sftp文件系统与版本控制同步 [英] Syncing sftp file system with version control

查看:144
本文介绍了将sftp文件系统与版本控制同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始为大学社会管理一个(小型)网站,显然(根据管理它的最后一个人),访问网站文件的方式是由SFTP管理。我使用Linux Mint / Nautilus,所以这不成问题。不过,我还有一个本地副本,用于在上传之前使用Apache / localhost测试我的更改(忽略目前无法完成的工作...)。我使用Git来跟踪我的更改。



有没有什么办法可以区分SFTP版本和我自己的版本,然后只更新已更改的文件(基本上通过SFTP进行某种同步),并可能将版本控制纳入其中?顺便说一句,我对此没有任何经验,所以解释会不胜感激。

谢谢!




<如果他们正在运行一个真正的SSH服务器,而不是仅仅使用SFTP的话服务器,那么您可以使用rsync将本地更改推送到远程。例如:

  cd / my / project /目录
rsync -PSauve ssh --exclude = .git * $ LOGNAME@example.com:/ var / www /

您可能还想使用 - 删除选项,但要谨慎,如果可能存在仅存在于服务器端的文件需要保留。



使用SFTP进行树操作



如果你不能使用rsync,你可以将上游文件复制到本地分支,区分它们,合并你想要的任何更改,然后将结果推回。例如:

  cd / my / project /目录
git checkout -b上游
sftp -r user@example.com:/ var / www / \ *。
git add。
git commit -m'从上游导入当前文件'
git checkout master
git diff upstream
:#根据需要合并或修改文件
sftp user @ example .com:/ var / www< <(echo'put -r *')



使用SCP而不是SFTP



如果您不能使用rsync,SCP通常比非交互式操作的SFTP更好。例如:

  scp -r。 user@example.com:/ var / www / 

SCP提供更清晰的界面,并支持符号链接SFTP没有),但是可能对你的用例有其他限制。特别是,它可能不打印它复制的空目录的名称;不管这件事是否由你决定。


I've recently started managing a (small-ish) website for a university society, and apparently (according to the last person who managed it) the way to access the files for the website is by SFTP. I use Linux Mint/Nautilus, so this is no problem. However I also have a local copy to test my changes with Apache/localhost before uploading (ignoring for the moment that I can't really get that to work...). I use Git to keep track of my changes.

Is there any way I can diff between the SFTP version and my own version, and then only update the changed files (basically some kind of sync over SFTP), and possibly incorporate the version control into that as well?

By the way, I have very little prior experience with this, so explanations would be appreciated. Same goes for reasonably fool-proof methods to do things, rather than necessarily the most sleek but horrible to configure way.

Thanks!

解决方案

Use Rsync Over SSH

If they are running a true SSH server, rather than an SFTP-only server, then you can use rsync to push your local changes to the remote. For example:

cd /my/project/directory
rsync -PSauve ssh --exclude=.git * $LOGNAME@example.com:/var/www/

You might also want to use the --delete option, but be cautious if there are likely to be files that exist only on the server side that need to be preserved.

Use SFTP for Tree Operations

If you can't use rsync, you could copy the upstream files into a local branch, diff them, merge whatever changes you want, and then push the results back up. For example:

cd /my/project/directory
git checkout -b upstream
sftp -r user@example.com:/var/www/\* .
git add .
git commit -m 'Import current files from upstream.'
git checkout master
git diff upstream
: # merge or modify files as needed
sftp user@example.com:/var/www < <(echo 'put -r *')

Use SCP instead of SFTP

If you can't use rsync, SCP is often much nicer than SFTP for non-interactive operations. For example:

scp -r . user@example.com:/var/www/

SCP offers a cleaner interface, and supports symlinks (which SFTP doesn't), but may have other limitations for your use case. In particular, it may not print the names of empty directories that it copies; whether or not that matters is up to you.

这篇关于将sftp文件系统与版本控制同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆