如何在没有本地仓库的情况下在远程运行 git 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5686336/
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 to run git commands on remote without having local repo
提问by NickSoft
I have a script called 'git-export' which helps me to export a remote repository. It is run like that:
我有一个名为“git-export”的脚本,它可以帮助我导出远程存储库。它是这样运行的:
git-export http://host.com/git-repo <-t tag or -b branch or -c commit> /local/dir
Before it was used to export local repository and I used these commands:
在用于导出本地存储库之前,我使用了以下命令:
to get commit from branch:
从分支获取提交:
git branch -v --no-abbrev|awk '(=="'$BRANCH'") || ( == "*" && == "'$BRANCH'"){if( == "*"){print ;}else{print ;}}'
or
或者
git rev-parse -q --verify $BRANCH^{commit}
to get commit by tag:
按标签提交:
git rev-parse -q --verify $TAG^{commit}
also I have scripts to list tags, versions (tags, starting with v), I use git branch -v to show branches....
我也有脚本来列出标签、版本(标签,以 v 开头),我使用 git branch -v 来显示分支....
Question is: How can I do these things on remote repository without having local. Is there some general way to query remote. For example: git --remote=http://host.com/repo branch -v
or git --remote=http://host.com/repo log
问题是:如何在没有本地存储库的情况下在远程存储库上执行这些操作。有没有一些通用的方法来查询远程。例如:git --remote=http://host.com/repo branch -v
或git --remote=http://host.com/repo log
Resion: If I want to install software on remote host I just want to
Resion:如果我想在远程主机上安装软件,我只想
- list versions, branches, etc
- export specific version/branch/commit and show SHA1 of the commit regardless which one of these I export (by export I mean
git archive --remote=<repo>|tar x
)
- 列出版本、分支等
- 导出特定版本/分支/提交并显示提交的 SHA1,无论我导出其中哪一个(我的意思是导出
git archive --remote=<repo>|tar x
)
edit:
编辑:
I don't want to actionalyl run the commands on remote. I want to use the remote repository with local commands and display it formatted.
我不想在远程操作上运行命令。我想将远程存储库与本地命令一起使用并格式化显示。
回答by Cascabel
You're looking for git ls-remote
. For example:
您正在寻找git ls-remote
. 例如:
$ git ls-remote git://git.kernel.org/pub/scm/git/git.git
4d8b32a2e1758236c4c1b714f179892e3bce982c HEAD
f75a94048af9e423a3d8cba694531d0d08bd82b4 refs/heads/html
810cae53e0f622d6804f063c04a83dbc3a11b7ca refs/heads/maint
70b5eebd65f2d47fd69073aed1d3da0f1fd7a017 refs/heads/man
4d8b32a2e1758236c4c1b714f179892e3bce982c refs/heads/master
b9f1b13437fd0b8b1857ffbdebb9e1adc50481f0 refs/heads/next
83a9d3226b19a683a9a783bde0784c2caf19e9a1 refs/heads/pu
2309986900ed1a5744b3a81c507943593000ce32 refs/heads/todo
d5aef6e4d58cfe1549adef5b436f3ace984e8c86 refs/tags/gitgui-0.10.0
3d654be48f65545c4d3e35f5d3bbed5489820930 refs/tags/gitgui-0.10.0^{}
33682a5e98adfd8ba4ce0e21363c443bd273eb77 refs/tags/gitgui-0.10.1
729ffa50f75a025935623bfc58d0932c65f7de2f refs/tags/gitgui-0.10.1^{}
...
(git.git has a lot of tags!)
You can limit yourself to branches with the --heads
option or tags with the --tags
option, or specify a pattern to select refs, for example to see only the git version tags from git.git, git ls-remote <url> refs/tags/v*
. Or you might already know exactly what ref you want: git ls-remote <url> HEAD
.
您可以将自己限制在带有--heads
选项的分支或带有选项的标签--tags
,或者指定一个模式来选择引用,例如只查看来自 git.git, 的 git 版本标签git ls-remote <url> refs/tags/v*
。或者你可能已经确切地知道你想要什么 ref: git ls-remote <url> HEAD
。
You can't run arbitrary commands on arbitrary remotes, though. The transfer protocols don't support that - they're designed to support listing refs and transferring objects (via packs). In particular, you won't be able to do anything analogous to rev-list
. You'll be limited to getting SHA1s for commits pointed to by refs.
但是,您不能在任意遥控器上运行任意命令。传输协议不支持 - 它们旨在支持列出引用和传输对象(通过包)。特别是,您将无法执行类似于rev-list
. 您将仅限于为 refs 指向的提交获取 SHA1。
回答by prometheus
You can use curl for checking if the specific url exists or not for example when i try to hit angularjs existing url
您可以使用 curl 检查特定 url 是否存在,例如当我尝试点击 angularjs 现有 url 时
$ curl -I https://github.com/angular/angularjs.org/tree/master/src
**HTTP/1.1 200 OK**
Server: GitHub.com
Date: Mon, 11 Aug 2014 15:22:40 GMT
When I hit on a wrong URL
当我点击错误的网址时
$ curl -I https://github.com/angular/angularjs.org/tree/master/abcd
**HTTP/1.1 404 Not Found**
Server: GitHub.com
Date: Mon, 11 Aug 2014 15:24:06 GMT
Hope this helps
希望这可以帮助