如何通过管道将 git 克隆传送到存档(tar 或 gzip)
我正在尝试为我的远程托管 git 存储库制作一个简单的备份脚本。在脚本中,我有几行目前看起来像这样:
git clone git@server:repo.git $DEST
tar czvf repo.tgz $DEST
rm -rf $DEST
有没有办法让这一切在一行中发生?我可以将 git clone 通过管道传输到 tar 命令中吗?我不需要克隆的目录,我只需要它的压缩存档。
我尝试过一些实验,但似乎无法弄清楚语法。
I am trying to make a simple backup script for my remotely hosted git repos. In the script I have a few lines that currently look like this:
git clone git@server:repo.git $DEST
tar czvf repo.tgz $DEST
rm -rf $DEST
Is there a way to make this all happen in one line? Can I pipe the git clone into the tar command? I don't need the cloned directory, I just want the compressed archive of it.
I've tried some experiments but can't seem to figure out the syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,你不能只通过管道 git clone ,因为它不会将其写出到标准输出。为什么你需要一句台词?他们非常擅长吹嘘你可以用一行代码做一些很酷的事情,但在现实世界中并不理想。
您可以执行如下操作,但您不会像在
git clone
中那样获得.git
:来自
git archive
手册No you cannot just pipe
git clone
because it does not write it out to the standard output. And why do you need a one-liner? They are great for boasting that you can do something cool in just one line, but not really ideal in real world.You can do something like below, but you would not get
.git
like you would in agit clone
:From
git archive
manual您可以通过
--remote
选项使用git archive
来实现此目的。您可以通过管道它来创建 zip 或 tar 或任何您喜欢的内容。
请参阅 git-archive(1) 手册页。
You can use
git archive
for this purpose with the--remote
option.You can pipe it to create zip or tar or whatever you like.
Please, see the git-archive(1) manual page.