rsync 出 git 存储库或 tar 存档
我有一个 git 存储库,我想将存储库的特定版本同步到目录中。基本上我想这样做:
$ 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
这样做的问题是它需要提取到临时目录并从中进行同步。这(理论上)是不必要的,并且对于一个巨大的 git 存储库来说需要很长时间并且需要大量的可用空间。我不只是想使用以下命令直接清除 ~/final-destination 和 tar 到其中:
$ git archive $MY_COMMIT | tar x -C ~/final-destination
因为这还需要大量不必要的工作,特别是如果 ~/final-destination 是远程目录。另一种选择是直接从存储库中检出特定修订版和 rsync:
$ git checkout $MY_COMMIT
$ rsync -a --exclude .git my-git-repo/ ~/final-destination
但我不想弄乱存储库的工作目录。我想在一个脚本中完成所有这些工作,当我在存储库中执行操作时,该脚本可以在后台运行。
所以。有没有办法直接从存储库的特定修订版本中进行 rsync。或者如果失败了,我可以以某种方式从 tar 存档中进行 rsync 而不必提取它吗?
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 directly 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不想从工作树中rsync
,恐怕您必须首先提取到临时目录。 (尽管当我在 Stack Overflow 上说这种事情时,不可避免地会有人想出更巧妙的东西:))你可以尝试的一件事是存储你的更改,签出你想要的提交,rsync,切换回上一个分支然后再次弹出存储:(
我还没有测试过,我应该警告你。)
If you don't want torsync
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:
(I haven't tested that, I should warn you.)