开发者

How do I pipe a git clone to archive (tar or gzip)

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.


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 a git clone :

git archive --format=tar --remote=git@server:repo.git master | tar -xf -

From git archive manual

--remote=<repo>

    Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜