我如何通过管道将 git clone 归档(tar 或 gzip)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5995301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I pipe a git clone to archive (tar or gzip)
提问by bryan kennedy
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 存储库制作一个简单的备份脚本。在脚本中,我有几行目前看起来像这样:
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.
有没有办法让这一切在一行中发生?我可以通过管道将 git clone 导入 tar 命令吗?我不需要克隆的目录,我只想要它的压缩存档。
I've tried some experiments but can't seem to figure out the syntax.
我尝试了一些实验,但似乎无法弄清楚语法。
回答by manojlds
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.
不,您不能只是管道,git clone
因为它不会将其写出到标准输出。为什么你需要一个单线?它们非常适合吹嘘你可以在一行中做一些很酷的事情,但在现实世界中并不理想。
You can do something like below, but you would not get .git
like you would in a git clone
:
您可以执行以下操作,但不会.git
像在git clone
:
git archive --format=tar --remote=git@server:repo.git master | tar -xf -
From git archive
manual
来自git archive
手册
--remote=<repo>
Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository.
回答by ralphtheninja
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.
您可以git archive
为此目的使用该--remote
选项。
您可以通过管道将其创建为 zip 或 tar 或任何您喜欢的文件。
Please, see the git-archive(1)manual page.
请参阅git-archive(1)手册页。