Git:从远程服务器获取特定修订 [英] Git: get specific revision from remote server

查看:223
本文介绍了Git:从远程服务器获取特定修订的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个测试架构。在这个系统中,VM必须测试代码的特定版本。虚拟机是完全干净的,没有本地(可更新)版本的回购。代码通过名为git的用户通过ssh托管在现场git服务器上。我完全控制这两台机器。



简单的解决方案是:

pre $ code> git clone --no-checkout git @ gitserver:reponame.git
git checkout 8e8fdea8f8367f4a179d2faddbaadba495d6bc12

这个方法可行,但确实太多了:它通过网络传输完整的历史记录,这是我想要尽可能避免的。

在我看来, git clone 的文档可以使用 - branch 选项,但是这不允许我指定特定的修订版。如果可以的话,这与 - 深度1 结合在一起对我很有用。



另一种方法是使用 git archive --remote 。我明白允许它进行任意修改的安全含义,在这种情况下这不是问题,所以我运行

 在git服务器上的git config --global --bool --add uploadArchive.allowUnreachable 1 

git user。



现在在git用户的shell中,我可以这样做:

  git archive --format tar.gz --remote reponame.git 8e8fdea8f8367f4a179d2faddbaadba495d6bc12 

另外,从我的虚拟机,我可以运行

  git archive --format tar.gz --remote git @ gitserver:reponame.git master 

然而,不行的是:

  git archive --format tar.gz --remote git @ gitserver:reponame.git 8e8fdea8f8367f4a179d2faddbaadba495d6bc12 

remote:fatal:no such ref:8e8fdea8f8367f4a179d2faddbaadba495d6bc12
remote:git upload-archive:archiver死于错误
致命错误:向客户端发送错误: git upload-archive:archiver死于错误

是的,我指向相同的回购站,该修订肯定是在回购中,它只是不适用于修订版号。有一件事情是,如果命令是通过ssh执行的,默认的〜/ .gitconfig 文件没有被读取,尽管我找不到任何信息这个。

目前我使用bash作为git用户的shell。它将在未来使用受限制的shell,但为了显示基本问题,我想使用一个普通的shell。



我对两个一般的评论感兴趣我应该如何获得对一台干净的机器的单一修订,以及解决不能使用git archive进行修订的特殊问题的解决方案。




编辑:torek给了我一些有关版本的想法(我在OSX上运行,使用git 1.8.5.2股票,并通过brew安装2.0.1),并且我在 git-upload-archive 来弄清楚发生了什么。包装脚本:

  / usr / local / bin / git --version> / tmp / version 
tee / tmp / stdin | / usr / local / bin / git-upload-archive$ 1| tee / tmp / stdout

并用调用git-archive - exec 选项来运行这个脚本。



编写的版本是2.0.1。然而,同样的问题仍然存在......从本地我可以用-remote和sha1调用git-archive iff uploadarchive.allowunreachable 被设置,远程我不能。有趣的是,在这两种情况下,请求(在 / tmp / stdin 中)完全相同,答复是不同的。据我所知,这是因为如果通过ssh启动,git-upload-archive不会选择正确的配置;这可以通过使用repo中的本地配置来显示,在这种情况下它可以工作(我在评论中表示这不起作用的原因是我确实正在拾取 / usr / bin / git -upload-archive ;不允许此配置标志的旧版本)。



这个问题实际上可以通过调用 / usr / local / bin / git upload-archive 而不是 / usr / local / bin / git-upload-archive 。这甚至可以作为参数提供给git-archive: - exec ='/ usr / local / bin / git-upload-archive'不起作用, --exec ='/ usr / local / bin / git upload-archive'确实如此。 我仍然对git-upload-archive为什么没有选择配置感兴趣(从学术角度)。可能这是一个应该报告给git项目的bug。

解决方案

为防万一别人遇到这个问题:90答案的%在编辑部分的问题中定义。最后的10%可能不值得真正潜入。我在这里重复的重点:$ b​​
$ b


  • 请注意,在OSX Mevericks上,默认GIT版本为< 2.0,因此不支持 uploadarchive.allowunreachable 标记。当通过SSH访问git时,它可能会根据是否启动交互式SSH会话来选择不同的版本(您的路径可能不同)。
  • upload-archive 不检查全局git配置中的 uploadarchive.allowunreachable 标志。这似乎是GIT中的一个错误。解决方案是不使用 git-upload-archive ,但是 git upload-archive (即使用git脚本,以upload-archive作为第一个参数)。一种方法是将 - exec ='/ usr / local / bin / git upload-archive'提供给 git archive code> call。

I'm setting up a test-architecture. In this system a VM has to test a specific revision of the code. The VM is completely clean, and does not have a local (updatable) version of the repo. The code is being hosted on an on-site git server, over ssh with a user named git. I have full control over both machines.

The easy solution is:

git clone --no-checkout git@gitserver:reponame.git
git checkout 8e8fdea8f8367f4a179d2faddbaadba495d6bc12

This works, but does too much: It transfers the full history over the network, something I want to avoid if at all possible.

It seems to me from the documentation that git clone can take a --branch option, but this doesn't allow me to specify a particular revision. If it would, this in combination with --depth 1 would work for me.

The alternative is to use git archive --remote. I understand the security implications of allowing this to get arbitrary revisions, and that is not a problem in this case, so I run

git config --global --bool --add uploadArchive.allowUnreachable 1

on the git server as the git user.

Now on the shell of the git user, I can do

git archive --format tar.gz --remote reponame.git 8e8fdea8f8367f4a179d2faddbaadba495d6bc12

Also, from my VM I can run

git archive --format tar.gz --remote git@gitserver:reponame.git master

However not working is:

git archive --format tar.gz --remote git@gitserver:reponame.git 8e8fdea8f8367f4a179d2faddbaadba495d6bc12

remote: fatal: no such ref: 8e8fdea8f8367f4a179d2faddbaadba495d6bc12
remote: git upload-archive: archiver died with error
fatal: sent error to the client: git upload-archive: archiver died with error

And yes, I'm pointing to the same repo, that revision definitely is in the repo, it will just not work with revision number. One thing that may be the case is that if the commands are executed over ssh, the default ~/.gitconfig file is not being read, although I could not find any information on this.

Currently I'm using bash as shell for the git user. It will work in the future with a restricted shell, but to show the basic problem, I wanted to use a normal shell.

I'm interested in both general remarks in how I should be getting a single revision to a clean machine, and a solution to the particular problem of not being able to use git archive with a revision.


EDIT: torek gave me some ideas about versions (I run on OSX, with git 1.8.5.2 stock, and 2.0.1 installed through brew), and I made a small wrapper script around git-upload-archive to figure out what was going on. The wrapper script:

/usr/local/bin/git --version > /tmp/version
tee /tmp/stdin | /usr/local/bin/git-upload-archive "$1" | tee /tmp/stdout

and calling the git-archive with the --exec option to run this script.

The version written is 2.0.1. The same problem persists however... From locally I can call git-archive with -remote and sha1 iff uploadarchive.allowunreachable is set, remotely I can't. Interestingly the request (in /tmp/stdin) is exactly the same in both cases, the reply is different. As far as I can see, this is because git-upload-archive is not picking up the correct config if started over ssh; this can be shown by using a local config in the repo, in which case it does work (my remark in the comments that this didn't work was because I was indeed picking up /usr/bin/git-upload-archive; the old version that doesn't allow this config flag).

The problem can actually be solved by calling /usr/local/bin/git upload-archive instead of /usr/local/bin/git-upload-archive. This can even be supplied as argument to git-archive: --exec='/usr/local/bin/git-upload-archive' doesn't work, --exec='/usr/local/bin/git upload-archive' does.

So problem works now. I would still be interested (from an academic point of view) in why git-upload-archive doesn't pick up the config. Possibly this is a bug that should be reported to the git project.

解决方案

Just in case someone else runs into this issue: 90% of the answer is defined in the question under the EDIT part. The last 10% is probably not worth really diving into. The important points I repeat here:

  • Take care that on OSX Mevericks the default GIT version is <2.0, and therefore doesn't support the uploadarchive.allowunreachable tag. When accessing git over SSH, it may select a different version depending on whether you start an interactive SSH session or not (your path may be different).
  • git-upload-archive doesn't check for the uploadarchive.allowunreachable flag in the global git config. This seems to be a bug in GIT. The solution is to not use git-upload-archive, but git upload-archive (i.e. use the git script, with upload-archive as first argument). One way to do this is to supply --exec='/usr/local/bin/git upload-archive' to the git archive call.

这篇关于Git:从远程服务器获取特定修订的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆