开发者

rsync out of git repository or tar archive

开发者 https://www.devze.com 2023-03-01 06:13 出处:网络
I have a git repository and I want to rsync a particular revision of the repository into a directory. Basically I want to do this:

I have a git repository and I want to rsync a particular revision of the repository into a directory. Basically I want to do this:

$ cd my-git-repo
$ git archive $MY_COMMIT > ~/blah.tar.gz
$ mkdir ~/tmp
$ cd ~/tmp
$ tar xf ~/blah.tar.gz
$ rsync -a ~/tmp/ ~/final-destination
$ cd
$ rm -r tmp

The problem with this is it requires extracting to a temporary directory and rsyncing from that. This is (theoretically) unnecessary and with a huge git repository takes a long time and requires a lot of free space. I don't just want to clear ~/final-destination and tar directly into it with:

$ git archive $MY_COMMIT | tar x -C ~/final-destination

because this also requires a lot of unnecessary work especially if ~/final-destination is a remote directory. Another option would be to checkout the particular revision and rsync 开发者_如何学Cdirectly out of the repository:

$ git checkout $MY_COMMIT
$ rsync -a --exclude .git my-git-repo/ ~/final-destination

but I'd rather not mess with the repository's working directory. I want to do all this in a script that may run in the background while I'm doing stuff in the respository.

So. Is there a way to rsync directly out of a particular revision of a repository. Or failing that can I somehow rsync from the tar archive without having to extract it?


If you don't want to rsync out of your working tree, I'm afraid that you're stuck with extracting to a temporary directory first. (Although when I say that kind of thing on Stack Overflow, inevitably someone comes up with something more ingenious :))

One thing you could try is to stash your changes, checkout the commit you want, rsync, switch back to the previous branch then pop the stash again:

set -e

git stash
git checkout $MY_COMMIT
rsync -a --exclude .git ./ ~/final-destination
git checkout -
git stash pop

(I haven't tested that, I should warn you.)

0

精彩评论

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